Rename user feature for PostgreSQL >= 7.4
authorsoranzo <soranzo>
Sun, 18 Jan 2004 16:03:01 +0000 (16:03 +0000)
committersoranzo <soranzo>
Sun, 18 Jan 2004 16:03:01 +0000 (16:03 +0000)
HISTORY
classes/database/Postgres74.php
lang/english.php
lang/italian.php
lang/recoded/english.php
lang/recoded/italian.php
users.php

diff --git a/HISTORY b/HISTORY
index 34a4b388a9378e14708e5c3263b7557e775f1424..7943b9d7ed28119f11f359466029da0285b62983 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -13,6 +13,7 @@ Features
 * Integration with the PostgreSQL statistics collector.  See
   table and index performance and usage information.
 * Display user session defaults for PostgreSQL >= 7.3
+* Rename user feature for PostgreSQL >= 7.4
 * Create functions returning arrays and table types
 
 Bugs
index d6a6c5b68198499f766279f4466c71792c775b67..c56e42cd1d6bcbee8276a1b762ed23dab7ea6159 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres74.php,v 1.22 2004/01/07 16:29:40 soranzo Exp $
+ * $Id: Postgres74.php,v 1.23 2004/01/18 16:03:10 soranzo Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -370,6 +370,40 @@ class Postgres74 extends Postgres73 {
                return $this->execute($sql);
        }
 
+       /**
+        * Adjusts a user's info and renames the user
+        * @param $username The username of the user to modify
+        * @param $password A new password for the user
+        * @param $createdb boolean Whether or not the user can create databases
+        * @param $createuser boolean Whether or not the user can create other users
+        * @param $expiry string Format 'YYYY-MM-DD HH:MM:SS'.  '' means never expire.
+        * @param $newname The new name of the user
+        * @return 0 success
+        * @return -1 transaction error
+        * @return -2 set user attributes error
+        * @return -3 rename error
+        */
+       function setRenameUser($username, $password, $createdb, $createuser, $expiry, $newname) {
+               $status = $this->beginTransaction();
+               if ($status != 0) return -1;
+
+               $status = $this->setUser($username, $password, $createdb, $createuser, $expiry);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -2;
+               }
+
+               if ($username != $newname){
+                       $status = $this->renameUser($username, $newname);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -3;
+                       }
+               }
+
+               return $this->endTransaction();
+       }
+
        // Capabilities
        function hasGrantOption() { return true; }
        function hasDomainConstraints() { return true; }
index 57cc09dd3bc1f5ef70439f2b0da40127611d98b8..242c5a5f379f818bff1ea28af23b847549f655d1 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.129 2004/01/07 16:29:40 soranzo Exp $
+        * $Id: english.php,v 1.130 2004/01/18 16:03:11 soranzo Exp $
         */
 
        // Language and character set
        $lang['strcreatedb'] = 'Create DB?';
        $lang['strexpires'] = 'Expires';
        $lang['strsessiondefaults'] = 'Session Defaults';
-       $lang['strnewname'] = 'New name';
        $lang['strnousers'] = 'No users found.';
-       $lang['strrename'] = 'Rename';
-       $lang['struserrenamed'] = 'User renamed.';
-       $lang['struserrenamedbad'] = 'Failed to rename user.';
        $lang['struserupdated'] = 'User updated.';
        $lang['struserupdatedbad'] = 'User update failed.';
        $lang['strshowallusers'] = 'Show all users';
index 0d299eef504c3c249b6cdfa4a6e1e93aaf64040e..ca1d004241472ae51aabaed513c6dc36f9a1cb1d 100644 (file)
@@ -4,7 +4,7 @@
         * Italian language file, based on the english language file for phpPgAdmin.
         * Nicola Soranzo [nsoranzo@tiscali.it]
          *
-        * $Id: italian.php,v 1.25 2004/01/07 16:29:41 soranzo Exp $
+        * $Id: italian.php,v 1.26 2004/01/18 16:03:11 soranzo Exp $
         */
 
        // Language and character set - Lingua e set di caratteri
        $lang['strcreatedb'] = 'Può creare DB?';
        $lang['strexpires'] = 'Scadenza';
        $lang['strsessiondefaults'] = 'Defaults della sessione';
-       $lang['strnewname'] = 'Nuovo nome';
        $lang['strnousers'] = 'Nessun utente trovato';
-       $lang['strrename'] = 'Rinomina';
-       $lang['struserrenamed'] = 'Utente rinominato.';
-       $lang['struserrenamedbad'] = 'Rinomina dell\'utente fallita.';
        $lang['struserupdated'] = 'Utente aggiornato.';
        $lang['struserupdatedbad'] = 'Aggiornamento utente fallito.';
        $lang['strshowallusers'] = 'Mostra tutti gli utenti';
index eb8d0f6fd3f66ff8bc1771f9d7fccfe60d881fef..f43f94ae8240ec766e119d5d472d0432f59dd60e 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.81 2004/01/07 16:29:41 soranzo Exp $
+        * $Id: english.php,v 1.82 2004/01/18 16:03:11 soranzo Exp $
         */
 
        // Language and character set
        $lang['strcreatedb'] = 'Create DB?';
        $lang['strexpires'] = 'Expires';
        $lang['strsessiondefaults'] = 'Session Defaults';
-       $lang['strnewname'] = 'New name';
        $lang['strnousers'] = 'No users found.';
-       $lang['strrename'] = 'Rename';
-       $lang['struserrenamed'] = 'User renamed.';
-       $lang['struserrenamedbad'] = 'Failed to rename user.';
        $lang['struserupdated'] = 'User updated.';
        $lang['struserupdatedbad'] = 'User update failed.';
        $lang['strshowallusers'] = 'Show all users';
index 5a801c6929bac767ab121f6f4c2d816010177499..b3bf433d3b5fc4f841eefd3bc5b13a63ccdc0d69 100644 (file)
@@ -4,7 +4,7 @@
         * Italian language file, based on the english language file for phpPgAdmin.
         * Nicola Soranzo [nsoranzo@tiscali.it]
          *
-        * $Id: italian.php,v 1.20 2004/01/07 16:29:41 soranzo Exp $
+        * $Id: italian.php,v 1.21 2004/01/18 16:03:11 soranzo Exp $
         */
 
        // Language and character set - Lingua e set di caratteri
        $lang['strcreatedb'] = 'Pu&ograve; creare DB?';
        $lang['strexpires'] = 'Scadenza';
        $lang['strsessiondefaults'] = 'Defaults della sessione';
-       $lang['strnewname'] = 'Nuovo nome';
        $lang['strnousers'] = 'Nessun utente trovato';
-       $lang['strrename'] = 'Rinomina';
-       $lang['struserrenamed'] = 'Utente rinominato.';
-       $lang['struserrenamedbad'] = 'Rinomina dell\'utente fallita.';
        $lang['struserupdated'] = 'Utente aggiornato.';
        $lang['struserupdatedbad'] = 'Aggiornamento utente fallito.';
        $lang['strshowallusers'] = 'Mostra tutti gli utenti';
index 62bfea19871cb03100887ae8705d0a58f9078835..df4910c89eded58dc3096b41363519fcaef5a936 100644 (file)
--- a/users.php
+++ b/users.php
@@ -3,7 +3,7 @@
        /**
         * Manage users in a database cluster
         *
-        * $Id: users.php,v 1.22 2004/01/03 19:15:44 soranzo Exp $
+        * $Id: users.php,v 1.23 2004/01/18 16:03:07 soranzo Exp $
         */
 
        // Include application functions
@@ -38,7 +38,7 @@
                        echo "<tr>\n\t<td class=\"data1\">", $misc->printVal($userdata->f[$data->uFields['uname']]), "</td>\n";
                        echo "\t<td class=\"data1\">", (($userdata->f[$data->uFields['usuper']]) ? $lang['stryes'] : $lang['strno']), "</td>\n";
                        echo "\t<td class=\"data1\">", (($userdata->f[$data->uFields['ucreatedb']]) ? $lang['stryes'] : $lang['strno']), "</td>\n";
-                       echo "\t<td class=\"data1\">", $misc->printVal($userdata->f[$data->uFields['uexpires']]), "</td>\n";
+                       echo "\t<td class=\"data1\">", ($userdata->f[$data->uFields['uexpires']] == 'infinity' ? '' : $misc->printVal($userdata->f[$data->uFields['uexpires']])), "</td>\n";
                        if ($data->hasUserSessionDefaults()) echo "\t<td class=\"data1\">", $misc->printVal($userdata->f[$data->uFields['udefaults']]), "</td>\n";
                        echo "</tr>\n</table>\n";
                }
                $userdata = &$data->getUser($_REQUEST['username']);
                
                if ($userdata->recordCount() > 0) {
+                       $canRename = $data->hasUserRename() && ($_REQUEST['username'] != $_SESSION['webdbUsername']);
                        $userdata->f[$data->uFields['usuper']] = $data->phpBool($userdata->f[$data->uFields['usuper']]);
                        $userdata->f[$data->uFields['ucreatedb']] = $data->phpBool($userdata->f[$data->uFields['ucreatedb']]);
 
                        if (!isset($_POST['formExpires'])){
+                               if ($canRename) $_POST['newname'] = $userdata->f[$data->uFields['uname']];
                                if ($userdata->f[$data->uFields['usuper']]) $_POST['formSuper'] = '';
                                if ($userdata->f[$data->uFields['ucreatedb']]) $_POST['formCreateDB'] = '';
-                               $_POST['formExpires'] = $userdata->f[$data->uFields['uexpires']];
+                               $_POST['formExpires'] = $userdata->f[$data->uFields['uexpires']] == 'infinity' ? '' : $userdata->f[$data->uFields['uexpires']];
                                $_POST['formPassword'] = '';
                        }
                
                        echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
                        echo "<table>\n";
                        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strusername']}</th>\n";
-                       echo "\t\t<td class=\"data1\">", $misc->printVal($userdata->f[$data->uFields['uname']]), "</td>\n\t</tr>\n";
+                       echo "\t\t<td class=\"data1\">", ($canRename ? "<input name=\"newname\" size=\"15\" value=\"" . htmlspecialchars($_POST['newname']) . "\" />" : $misc->printVal($userdata->f[$data->uFields['uname']])), "</td>\n\t</tr>\n";
                        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strsuper']}</th>\n";
                        echo "\t\t<td class=\"data1\"><input type=\"checkbox\" name=\"formSuper\"", 
                                (isset($_POST['formSuper'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>\n";
        function doSaveEdit() {
                global $data, $lang;
                
-               // Check password
-               if ($_POST['formPassword'] != $_POST['formConfirm'])
+               // Check name and password
+               if (isset($_POST['newname']) && $_POST['newname'] == '')
+                       doEdit($lang['struserneedsname']);
+               else if ($_POST['formPassword'] != $_POST['formConfirm'])
                        doEdit($lang['strpasswordconfirm']);
-               else {          
-                       $status = $data->setUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires']);
+               else {
+                       if (isset($_POST['newname'])) $status = $data->setRenameUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires'], $_POST['newname']);
+                       else $status = $data->setUser($_POST['username'], $_POST['formPassword'], isset($_POST['formCreateDB']), isset($_POST['formSuper']), $_POST['formExpires']);
                        if ($status == 0)
                                doDefault($lang['struserupdated']);
                        else
                                echo "<tr>\n\t<td class=\"data{$id}\">", $misc->printVal($users->f[$data->uFields['uname']]), "</td>\n";
                                echo "\t<td class=\"data{$id}\">", ($users->f[$data->uFields['usuper']]) ? $lang['stryes'] : $lang['strno'], "</td>\n";
                                echo "\t<td class=\"data{$id}\">", ($users->f[$data->uFields['ucreatedb']]) ? $lang['stryes'] : $lang['strno'], "</td>\n";
-                               echo "\t<td class=\"data{$id}\">", $misc->printVal($users->f[$data->uFields['uexpires']]), "</td>\n";
+                               echo "\t<td class=\"data{$id}\">", ($users->f[$data->uFields['uexpires']] == 'infinity' ? '' : $misc->printVal($users->f[$data->uFields['uexpires']])), "</td>\n";
                                if ($data->hasUserSessionDefaults()) echo "\t<td class=\"data{$id}\">", $misc->printVal($users->f[$data->uFields['udefaults']]), "</td>\n";
                                echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=edit&amp;username=",
                                        urlencode($users->f[$data->uFields['uname']]), "\">{$lang['stralter']}</a></td>\n";
                        break;
                case 'confirm_drop':
                        doDrop(true);
-                       break;                  
+                       break;
                case 'save_edit':
                        if (isset($_REQUEST['cancel'])) doDefault();
                        else doSaveEdit();