Index: /trunk/admin/user_list.php
===================================================================
--- /trunk/admin/user_list.php	(revision 25115)
+++ /trunk/admin/user_list.php	(revision 25116)
@@ -205,6 +205,9 @@
     else
     {
-      $page['errors'] = register_user(
-        $_POST['login'], $_POST['password'], $_POST['email'], false);
+      register_user($_POST['login'],
+                    $_POST['password'],
+                    $_POST['email'],
+                    false,
+                    $page['errors']);
 
       if (count($page['errors']) == 0)
@@ -219,6 +222,9 @@
   if (isset($_POST['submit_add']))
   {
-    $page['errors'] = register_user(
-      $_POST['login'], $_POST['password'], $_POST['email'], false);
+    register_user($_POST['login'],
+                  $_POST['password'],
+                  $_POST['email'],
+                  false,
+                  $page['errors']);
 
     if (count($page['errors']) == 0)
Index: /trunk/include/functions_user.inc.php
===================================================================
--- /trunk/include/functions_user.inc.php	(revision 25115)
+++ /trunk/include/functions_user.inc.php	(revision 25116)
@@ -120,6 +120,16 @@
    return $users_found[0];
 }
+
+/**
+ * create a new user
+ * @param string $login
+ * @param string $password
+ * @param string $mail_adress
+ * @param bool $with_notifications
+ * @param &array $errors
+ * @return int|bool
+ */
 function register_user($login, $password, $mail_address,
-  $with_notification = true, $errors = array())
+  $with_notification = true, &$errors = array())
 {
   global $conf;
@@ -172,14 +182,6 @@
   if (count($errors) == 0)
   {
-    // what will be the inserted id ?
-    $query = '
-SELECT MAX('.$conf['user_fields']['id'].') + 1
-  FROM '.USERS_TABLE.'
-;';
-    list($next_id) = pwg_db_fetch_row(pwg_query($query));
-
     $insert =
       array(
-        $conf['user_fields']['id'] => $next_id,
         $conf['user_fields']['username'] => pwg_db_real_escape_string($login),
         $conf['user_fields']['password'] => $conf['password_hash']($password),
@@ -188,8 +190,8 @@
 
     single_insert(USERS_TABLE, $insert);
+    $user_id = pwg_db_insert_id();
 
     // Assign by default groups
-    {
-      $query = '
+    $query = '
 SELECT id
   FROM '.GROUPS_TABLE.'
@@ -197,14 +199,13 @@
   ORDER BY id ASC
 ;';
-      $result = pwg_query($query);
-
-      $inserts = array();
-      while ($row = pwg_db_fetch_assoc($result))
-      {
-          $inserts[] = array(
-            'user_id' => $next_id,
-            'group_id' => $row['id']
-          );
-      }
+    $result = pwg_query($query);
+
+    $inserts = array();
+    while ($row = pwg_db_fetch_assoc($result))
+    {
+        $inserts[] = array(
+          'user_id' => $user_id,
+          'group_id' => $row['id']
+        );
     }
 
@@ -220,5 +221,5 @@
         $override=null;
     }
-    create_user_infos($next_id, $override);
+    create_user_infos($user_id, $override);
 
     if ($with_notification and $conf['email_admin_on_new_user'])
@@ -245,12 +246,16 @@
     trigger_action('register_user',
       array(
-        'id'=>$next_id,
+        'id'=>$user_id,
         'username'=>$login,
         'email'=>$mail_address,
        )
       );
-  }
-
-  return $errors;
+      
+    return $user_id;
+  }
+  else
+  {
+    return false;
+  }
 }
 
Index: /trunk/include/user.inc.php
===================================================================
--- /trunk/include/user.inc.php	(revision 25115)
+++ /trunk/include/user.inc.php	(revision 25116)
@@ -61,6 +61,5 @@
     if (!($user['id'] = get_userid($remote_user)))
     {
-      register_user($remote_user, '', '', false);
-      $user['id'] = get_userid($remote_user);
+      $user['id'] = register_user($remote_user, '', '', false);
     }
   }
Index: /trunk/register.php
===================================================================
--- /trunk/register.php	(revision 25115)
+++ /trunk/register.php	(revision 25116)
@@ -53,10 +53,9 @@
   }
 
-  $page['errors'] =
-      register_user($_POST['login'],
-                    $_POST['password'],
-                    $_POST['mail_address'],
-                    true,
-                    $page['errors']);
+  register_user($_POST['login'],
+                $_POST['password'],
+                $_POST['mail_address'],
+                true,
+                $page['errors']);
 
   if (count($page['errors']) == 0)
