<?php 
    # $Id: users_LISTING.php,v 1.4 2007/01/14 15:09:20 jarda Exp $

    /* Page that displays list of existing user accounts
    */

    require_once('structuredPage.inc.php');

    class PageClass extends EditUserAccountsStructuredPage
    {
        
        function getTitle()
        {
            return 'Users listing';
        }
        
        
        function printContents()
        {
            $userInfo = $this->getUserInfo();

            $loggedUserId = $userInfo['userid'];
            
            echo "<table border=\"1\">\n";
            echo "<tr><th>Login</th><th>Database edit</th><th>Users edit</th><th>Password change</th><th>Edit</th><th>Delete</th></tr>\n";

            $db = connect();

            $query = "SELECT * from bDbUser ORDER BY login";

            $recordSet = $db->Execute($query);

            while ($row = $recordSet->FetchRow()) {
                $this->addRow($loggedUserId, $row);
            }
            
            echo "</table>\n";

            echo "<br>\n";

            echo "<form action=\"user_NEW.php\" method=\"post\">\n";    
            echo "<input type=\"submit\" value=\"New\" name=\"new\">";
            echo "</form>\n";
        }


        /* Adds a row to the displayed table of user accounts
        */
        function addRow($loggedUserId, $row)
        {
            $canEditDB = $row['caneditdatabase'] ? 'YES' : 'NO';
            $canEditUserAccounts = $row['canedituseraccounts'] ? 'YES' : 'NO';
            $canChangeOwnPassword = $row['canchangeownpassword'] ? 'YES' : 'NO';
            
            echo "<tr valign=\"middle\"><td>$row[login]</td><td>$canEditDB</td><td>$canEditUserAccounts</td><td>$canChangeOwnPassword</td><td>";
            if ($row[id] == $loggedUserId)
            {
                echo "&nbsp;</td><td>&nbsp;";
            }
            else
            {
                echo "<form action=\"user_EDIT.php\" method=\"post\">";
                echo "<input type=\"hidden\" name=\"userId\" value=\"$row[id]\">\n";
                echo "<input type=\"submit\" value=\"Edit\" name=\"edit\">";
                echo "</form>";
                echo "</td><td>";
                echo "<form action=\"user_DELETE.php\" method=\"post\">";
                echo "<input type=\"hidden\" name=\"userId\" value=\"$row[id]\">\n";
                echo "<input type=\"submit\" value=\"Delete\" name=\"delete\">";
                echo "</form>";
            }
                
            echo("</td></tr>\n");
        }
        
    }

    launchPage();
    
    # vim:enc=iso8859-2:fenc=iso8859-2:
?>
