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

Annotation of /FigWebServices/users.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3