* LISTUSR
* LIST.USERS verb
* Copyright (c) 2002 Ladybridge Systems, All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* 
* Ladybridge Systems can be contacted via the www.openqm.com web site.
* 
* START-HISTORY:
* 13 Oct 04  2.0-5 Use message handler.
* 16 Sep 04  2.0-1 OpenQM launch. Earlier history details suppressed.
* END-HISTORY
*
* START-DESCRIPTION:
*
* LIST.USERS
*
* END-DESCRIPTION
*
* START-CODE

$internal
$flags trusted
program $list.users
$catalog $LISTUSR

$include int$keys.h
$include parser.h
$include err.h

   prompt ''

   parser = "!PARSER"

   @system.return.code = -ER$ARGS     ;* Preset for argument errors


   if not(kernel(K$ADMINISTRATOR,-1)) then
      stop sysmsg(2001) ;* Command requires administrator privileges
   end

   if not(kernel(K$SECURE, -1)) then
      display sysmsg(6059) ;* WARNING: System is running in insecure mode
   end

   openpath @qmsys:@ds:'$LOGINS' to lgn.f else
      @system.return.code = -status()
      stop sysmsg(6050) ;* Cannot open $LOGINS register in QMSYS account
   end

   call @parser(parser$reset, 0, @sentence, 0)
   call @parser(parser$get.token, token.type, token, keyword) ;* Verb

   * Check for unwanted command arguments

   call @parser(parser$get.token, token.type, token, keyword)
   if token.type # PARSER$END then
      stop sysmsg(2018, token) ;* Unexpected token (xx)
   end

   * Process users

* 0         1         2         3         4         5         6         7
* 01234567890123456789012345678901234567890123456789012345678901234567890123456789
* User name.......................  Login account...  Last login.....  Admin
* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxx  12 Feb 02 12:34   Yes

   sselect lgn.f
   user.reported = @false
   loop
      readnext lgn.id else exit
      if lgn.id[1,1] = '$' then continue  ;* Ignore system records

      if not(user.reported) then
         display sysmsg(6060)  ;* User name.......................  Login account...  Last login.....  Admin
         user.reported = @true
      end

      s = fmt(lgn.id, '32L') : '  '
      read lgn.rec from lgn.f, lgn.id then
         s := fmt(lgn.rec<LGN$FORCE.ACCOUNT>, '16L') : '  '
         s := fmt(oconv(lgn.rec<LGN$DATE>, 'D2 DMYL[,A3]') : ' ' : oconv(lgn.rec<LGN$TIME>, 'MT'), '15L') : '   '
         s := sysmsg(if lgn.rec<LGN$ADMIN> then 2057 else 2058)  ;* Yes / No
         display trimb(s)
      end else
         display '????'
      end
   repeat

   if not(user.reported) then
      display sysmsg(6061) ;* There are no users in the register
   end

   close lgn.f

   @system.return.code = 0
   return
end

* END-CODE
