add users to groups when they're created
authorchriskl <chriskl>
Tue, 7 Jan 2003 08:56:04 +0000 (08:56 +0000)
committerchriskl <chriskl>
Tue, 7 Jan 2003 08:56:04 +0000 (08:56 +0000)
TODO
classes/database/Postgres.php
lang/english.php
public_html/groups.php

diff --git a/TODO b/TODO
index eeb118bacb6e5d11e508d9fc683506dad7a40498..fa42b8498800aef62b43aef2df42deb26fe14df5 100644 (file)
--- a/TODO
+++ b/TODO
@@ -29,7 +29,7 @@ Groups
 
 * Group properties / membership
 * Alter group
-* Allow selecting of members when creating group
+* -Allow selecting of members when creating group (chriskl)
 
 Permissions [ Robert ]
 -----------
index 903011e58e3584f8d7c9fefe6571654b07a64416..fab174eef3e8305426d8b06dd5caf634eeca6252 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.32 2003/01/07 05:43:30 chriskl Exp $
+ * $Id: Postgres.php,v 1.33 2003/01/07 08:56:04 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -1107,13 +1107,19 @@ class Postgres extends BaseDB {
        /**
         * Creates a new group
         * @param $groname The name of the group
+        * @param $users An array of users to add to the group
         * @return 0 success
         */
-       function createGroup($groname) {
-               $this->clean($groname);
+       function createGroup($groname, $users) {
+               $this->fieldClean($groname);
 
                $sql = "CREATE GROUP \"{$groname}\"";
                
+               if (is_array($users) && sizeof($users) > 0) {
+                       $this->arrayClean($users);
+                       $sql .= ' WITH USER "' . join('", "', $users) . '"';                    
+               }               
+               
                return $this->execute($sql);
        }       
        
@@ -1123,7 +1129,7 @@ class Postgres extends BaseDB {
         * @return 0 success
         */
        function dropGroup($groname) {
-               $this->clean($groname);
+               $this->fieldClean($groname);
                
                $sql = "DROP GROUP \"{$groname}\"";
                
index 893996f37e4a09ffae5667a54ac1fe7d4eec5439..3c8915b4be1250a4b9c989ebdb5c953c409b5f94 100755 (executable)
@@ -4,7 +4,7 @@
         * Language template file for WebDB.  Use this to base language
         * files.
         *
-        * $Id: english.php,v 1.31 2003/01/07 05:50:06 chriskl Exp $
+        * $Id: english.php,v 1.32 2003/01/07 08:56:05 chriskl Exp $
         */
 
        $appLang = 'English';
@@ -95,6 +95,7 @@
        $strConfDropGroup = 'Are you sure you want to drop the group "%s"?';    
        $strGroupDropped = 'Group dropped.';
        $strGroupDroppedBad = 'Group drop failed.';
+       $strMembers = 'Members';
 
        // Privilges
        $strPrivileges = 'Privileges';
index 53dd950dca7050f58539178cea7338fd19f25f4f..90d9fb969b44328beaa8885a01efad4012de3413 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage groups in a database cluster
         *
-        * $Id: groups.php,v 1.1 2003/01/07 05:49:38 chriskl Exp $
+        * $Id: groups.php,v 1.2 2003/01/07 08:56:06 chriskl Exp $
         */
 
        // Include application functions
         * Displays a screen where they can enter a new group
         */
        function doCreate($msg = '') {
-               global $data, $misc, $formName;
-               global $PHP_SELF, $strName, $strGroups, $strCreateGroup, $strShowAllGroups;
+               global $data, $misc;
+               global $PHP_SELF, $strName, $strGroups, $strCreateGroup, $strShowAllGroups, $strMembers, $strNoUsers;
                
-               if (!isset($formName)) $formName = '';
+               if (!isset($_POST['formName'])) $_POST['formName'] = '';
+               if (!isset($_POST['formMembers'])) $_POST['formMembers'] = array();
+
+               // Fetch a list of all users in the cluster
+               $users = &$data->getUsers();
                
                echo "<h2>{$strGroups}: {$strCreateGroup}</h2>\n";
                $misc->printMsg($msg);
                echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
                echo "<table>\n";
                echo "<tr><th class=\"data\">{$strName}</th>\n";
-               echo "<td class=\"data\"><input size=\"32\" maxlength=\"{$data->_maxNameLen}\" name=\"formName\" value=\"", htmlspecialchars($formName), "\" /></td></tr>\n";
+               echo "<td class=\"data\"><input size=\"32\" maxlength=\"{$data->_maxNameLen}\" name=\"formName\" value=\"", htmlspecialchars($_POST['formName']), "\" /></td></tr>\n";
+               if ($users->recordCount() > 0) {
+                       echo "<tr><th class=\"data\">{$strMembers}</th>\n";
+                       echo "<td class=\"data\">\n";
+                       while (!$users->EOF) {
+                               $username = $users->f[$data->uFields['uname']];
+                               echo "<input type=\"checkbox\" name=\"formMembers[", htmlspecialchars($username), "]\"", 
+                                       (isset($_POST['formMembers'][$username]) ? ' checked' : ''), ">", htmlspecialchars($username), "<br>\n";
+                               $users->moveNext();
+                       }               
+                       echo "</td></tr>\n";
+               }
                echo "</table>\n";
                echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
                echo "<input type=\"submit\" value=\"Save\" /> <input type=\"reset\" /></p>\n";
                global $data;
                global $strGroupNeedsName, $strGroupCreated, $strGroupCreatedBad;
                
+               if (!isset($_POST['formMembers'])) $_POST['formMembers'] = array();
+
                // Check form vars
                if (trim($_POST['formName']) == '')
                        doCreate($strGroupNeedsName);
                else {          
-                       $status = $data->createGroup($_POST['formName']);
+                       $status = $data->createGroup($_POST['formName'], array_keys($_POST['formMembers']));
                        if ($status == 0)
                                doDefault($strGroupCreated);
                        else