[Bio] / FigWebServices / users.cgi Repository:
ViewVC logotype

Annotation of /FigWebServices/users.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download)

1 : olson 1.1 #
2 :     # Simple user management CGI.
3 :     #
4 :     # This allows one to manage a set of per-user parameters that one might be interested
5 :     # in. Currently we support:
6 :     #
7 :     # accept_assignments True if we accept assignments from this user on p2p transfers.
8 :     # Defaults to true for users that aren't one of the
9 :     # pseudo-users billogix, automated_assignment(s), master, fix,
10 :     # last_release
11 :     #
12 :    
13 :     use strict;
14 :    
15 :     use UserDB;
16 :     use FIG;
17 :     use HTML;
18 :     use CGI;
19 :    
20 :     my @pseudo_users = qw(billogix automated_assignment automated_assignments master fix last_release);
21 :     my %pseudo_users;
22 :     map { $pseudo_users{$_}++; } @pseudo_users;
23 :    
24 :     my $fig = new FIG;
25 :     my $cgi = new CGI;
26 :     my $udb = new UserDB($fig);
27 :    
28 :     my @html;
29 :    
30 :     push(@html, $cgi->title("SEED User Management"),
31 :     $cgi->h1("SEED User Management"));
32 :    
33 :    
34 :     #
35 :     # If we're coming in thru a submit button being pressed, need to scan thru
36 :     # the old_values and compare to the checked state.
37 :     #
38 :    
39 :     if ($cgi->param('submit'))
40 :     {
41 :     my $need_write;
42 :     for my $param ($cgi->param)
43 :     {
44 :     if ($param =~ /^aa_old_(\S+)/)
45 :     {
46 :     my $user = $1;
47 :     my $form_aa = $cgi->param("aa_$user") ? 1 : 0;
48 :     my $old_aa = $cgi->param($param);
49 :     my $udb_aa = $udb->get_user_param($user, 'accept_assignments');
50 :    
51 :     if ($old_aa != $form_aa)
52 :     {
53 :     $udb->set_user_param($user, 'accept_assignments', $form_aa);
54 :     $need_write++;
55 :     }
56 :     }
57 :     }
58 :     $udb->write() if $need_write;
59 :     }
60 :    
61 :    
62 :    
63 :     push(@html, $cgi->start_form(-action => 'users.cgi'));
64 :     build_user_table($fig, $cgi, \@html);
65 :    
66 :     push(@html, $cgi->submit(-name => "submit",
67 :     -value => 'Submit'));
68 :    
69 :     push(@html, $cgi->end_form);
70 :    
71 :     &HTML::show_page($cgi, \@html);
72 :     exit;
73 :    
74 :     sub build_user_table
75 :     {
76 :     my($fig, $cgi, $html) = @_;
77 :    
78 :     my $need_write;
79 :    
80 :     my(@rows);
81 :    
82 :     for my $user (sort $udb->get_users())
83 :     {
84 :     my $aa = $udb->get_user_param($user, 'accept_assignments');
85 :     my $aa_cb_name = "aa_$user";
86 :     my $aa_oldval_name = "aa_old_$user";
87 :    
88 :     #
89 :     # If we've not set a value for aa yet, default it to on unless user is a pseudo-user.
90 :     #
91 :    
92 :     if (!defined($aa))
93 :     {
94 :     warn "setting a default\n";
95 :     $aa = defined($pseudo_users{$user}) ? 0 : 1;
96 :     $udb->set_user_param($user, 'accept_assignments', $aa);
97 :     $need_write++;
98 :     }
99 :    
100 :     my $aa_checkbox = $cgi->checkbox(-name => "aa_$user",
101 :     -checked => $aa,
102 :     -override => 1,
103 :     -label => '');
104 :     push(@rows, [$user, "\@align=center:$aa_checkbox"]);
105 :     push(@$html, $cgi->hidden(-name => $aa_oldval_name,
106 :     -value => $aa));
107 :     }
108 :    
109 :     #
110 :     # If we set any defaults, write the user db.
111 :     #
112 :     $udb->write() if $need_write;
113 :    
114 :     push(@$html, HTML::make_table(["User", "Assignments accepted"], \@rows));
115 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3