3 # This CGI generated the HTML for choosing a user or list of users.
5 BEGIN { push(@INC, ".."); };
8 $trust_unknown_referers = 1;
10 if (&get_product_name() eq 'usermin') {
11 &switch_to_remote_user();
13 &ReadParse(undef, undef, 2);
14 %access = &get_module_acl();
17 # selecting multiple users.
18 if ($in{'frame'} == 0) {
22 @ul = split(/\s+/, $in{'user'});
24 print "sel = new Array($len);\n";
25 print "selr = new Array($len);\n";
26 for($i=0; $i<$len; $i++) {
28 "e_escape($ul[$i], '"')."\";\n";
29 @uinfo = getpwnam($ul[$i]);
31 print "selr[$i] = \"".
32 "e_escape($uinfo[6])."\";\n";
35 print "selr[$i] = \"???\";\n";
39 print "<title>$text{'users_title1'}</title>\n";
40 print "<frameset cols='50%,50%'>\n";
41 print "<frame src=\"user_chooser.cgi?frame=1&multi=1\">\n";
42 print "<frameset rows='*,50' frameborder=no>\n";
43 print " <frame src=\"user_chooser.cgi?frame=2&multi=1\">\n";
44 print " <frame src=\"user_chooser.cgi?frame=3&multi=1\" scrolling=no>\n";
45 print "</frameset>\n";
46 print "</frameset>\n";
48 elsif ($in{'frame'} == 1) {
49 # list of all users to choose from
52 print "function adduser(u, r)\n";
54 print "top.sel[top.sel.length] = u\n";
55 print "top.selr[top.selr.length] = r\n";
56 print "top.frames[1].location = top.frames[1].location\n";
57 print "return false;\n";
60 print "<font size=+1>$text{'users_all'}</font>\n";
61 print "<table width=100%>\n";
62 foreach $u (&get_users_list()) {
63 if ($in{'user'} eq $u->[0]) { print "<tr $cb>\n"; }
64 else { print "<tr>\n"; }
65 $u->[6] =~ s/'/'/g;
66 print "<td width=20%><a href=\"\" onClick='return adduser(\"$u->[0]\", \"$u->[6]\")'>$u->[0]</a></td>\n";
67 print "<td>$u->[6]</td> </tr>\n";
72 elsif ($in{'frame'} == 2) {
75 print "<font size=+1>$text{'users_sel'}</font>\n";
81 sel2 = new Array(); selr2 = new Array();
82 for(k=0,l=0; k<top.sel.length; k++) {
85 selr2[l] = top.selr[k];
89 top.sel = sel2; top.selr = selr2;
90 top.frames[1].location = top.frames[1].location;
93 for(i=0; i<top.sel.length; i++) {
94 document.write("<tr>\n");
95 document.write("<td><a href=\"\" onClick='return sub("+i+")'>"+top.sel[i]+"</a></td>\n");
96 document.write("<td>"+top.selr[i]+"</td>\n");
103 elsif ($in{'frame'} == 3) {
104 # output OK and Cancel buttons
107 print "function qjoin(l)\n";
109 print "rv = \"\";\n";
110 print "for(i=0; i<l.length; i++) {\n";
111 print " if (rv != '') rv += ' ';\n";
112 print " if (l[i].indexOf(' ') < 0) rv += l[i];\n";
113 print " else rv += '\"'+l[i]+'\"'\n";
115 print "return rv;\n";
119 print "<input type=button value=\"$text{'users_ok'}\" ",
120 "onClick='top.opener.ifield.value = qjoin(top.sel); ",
122 print "<input type=button value=\"$text{'users_cancel'}\" ",
123 "onClick='top.close()'>\n";
124 print " <input type=button value=\"$text{'users_clear'}\" onClick='top.sel = new Array(); top.selr = new Array(); top.frames[1].location = top.frames[1].location'>\n";
130 # selecting just one user .. display a list of all users to choose from
131 &popup_header($text{'users_title2'});
133 print "function select(f)\n";
135 print "top.opener.ifield.value = f;\n";
136 print "top.close();\n";
137 print "return false;\n";
140 print "<table width=100%>\n";
141 foreach $u (&get_users_list()) {
142 if ($in{'user'} eq $u->[0]) { print "<tr $cb>\n"; }
143 else { print "<tr>\n"; }
144 print "<td width=20%><a href=\"\" onClick='return select(\"$u->[0]\")'>$u->[0]</a></td>\n";
145 print "<td>$u->[6]</td> </tr>\n";
153 local(@uinfo, @users, %ucan, %found);
154 if ($access{'uedit_mode'} == 2 || $access{'uedit_mode'} == 3) {
155 map { $ucan{$_}++ } split(/\s+/, $access{'uedit'});
158 while(@uinfo = getpwent()) {
159 if ($access{'uedit_mode'} == 5 && $access{'uedit'} !~ /^\d+$/) {
160 # Get group for matching by group name
161 @ginfo = getgrgid($uinfo[3]);
163 if ($access{'uedit_mode'} == 0 ||
164 $access{'uedit_mode'} == 2 && $ucan{$uinfo[0]} ||
165 $access{'uedit_mode'} == 3 && !$ucan{$uinfo[0]} ||
166 $access{'uedit_mode'} == 4 &&
167 (!$access{'uedit'} || $uinfo[2] >= $access{'uedit'}) &&
168 (!$access{'uedit2'} || $uinfo[2] <= $access{'uedit2'}) ||
169 $access{'uedit_mode'} == 5 &&
170 ($access{'uedit'} =~ /^\d+$/ && $uinfo[3] == $access{'uedit'} ||
171 $ginfo[0] eq $access{'uedit'})) {
172 push(@users, [ @uinfo ]) if (!$found{$uinfo[0]}++);
175 endpwent() if ($gconfig{'os_type'} ne 'hpux');
176 return sort { $a->[0] cmp $b->[0] } @users;