]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/cgi-bin/superuser-setup.cgi
config updates...
[working/Evergreen.git] / Open-ILS / src / cgi-bin / superuser-setup.cgi
1 #!/usr/bin/perl
2 use strict;
3
4 use OpenILS::Application::Storage;
5 use OpenILS::Application::Storage::CDBI;
6
7 # I need to abstract the driver loading away...
8 use OpenILS::Application::Storage::Driver::Pg;
9
10 use CGI qw/:standard start_*/;
11
12 OpenILS::Application::Storage::CDBI->connection('dbi:Pg:host=10.0.0.2;dbname=open-ils-dev', 'postgres');
13 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
14
15 my $cgi = new CGI;
16
17 #-------------------------------------------------------------------------------
18 # HTML part
19 #-------------------------------------------------------------------------------
20
21 print <<HEADER;
22 Content-type: text/html
23
24 <html>
25
26 <head>
27         <style>
28                 table.table_class {
29                         border: dashed lightgrey 1px;
30                         background-color: #EEE;
31                         border-collapse: collapse;
32                 }
33
34                 deactivated {
35                         color: lightgrey;
36                 }
37
38                 tr.row_class td {
39                         border: solid lightgrey 1px;
40                 }
41                 
42                 tr.header_class th {
43                         background-color: lightblue;
44                 }
45
46         </style>
47 <body style='padding: 25px;'>
48
49 <h1>Superuser Setup</h1>
50 <hr/>
51
52 HEADER
53
54 #-------------------------------------------------------------------------------
55 # setup part
56 #-------------------------------------------------------------------------------
57
58 my %user_cols = (
59         qw/id SysID active Active usrname Username profile UserProfile passwd Password prefix Prefix
60            first_given_name FirstName second_given_name MiddleName family_name LastName
61            suffix Suffix dob Birthdate email Email day_phone DayPhone evening_phone EveningPhone
62            other_phone CellPhone home_ou HomeLib ident_type IdentificationType
63            ident_value Identification_value photo_url PhotoURL/ );
64
65 my @col_display_order = (
66         qw/id active usrname passwd profile prefix first_given_name second_given_name
67            family_name suffix dob email day_phone evening_phone other_phone
68            home_ou ident_type ident_value photo_url/ );
69
70 my @required_cols = ( qw/profile usrname passwd profile ident_type ident_value
71                          first_given_name family_name dob/ );
72
73 #-------------------------------------------------------------------------------
74 # Logic part
75 #-------------------------------------------------------------------------------
76
77 if (my $action = $cgi->param('action')) {
78         if ( $action eq 'Update Selected' ) {
79                 for my $id ( ($cgi->param('id')) ) {
80                         my $u = actor::user->retrieve($id);
81                         for my $col ( @col_display_order ) {
82                                 $u->$col( $cgi->param($col."_$id") );
83                         }
84                         $u->active( 'f' ) unless ($cgi->param("active_$id"));
85                         $u->update;
86                 }
87         } elsif ( $action eq 'Add New' ) {
88                 my $u = actor::user->create(
89                         { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %user_cols }
90                 );
91                 $u->super_user('t');
92                 $u->update;
93         }
94 }
95
96
97 #-------------------------------------------------------------------------------
98 # Form part
99 #-------------------------------------------------------------------------------
100 {
101         #-----------------------------------------------------------------------
102         # User form
103         #-----------------------------------------------------------------------
104         print   "<form method='POST'>".
105                 "<table class='table_class'><tr class='header_class'>\n";
106         
107         for my $col ( @col_display_order ) {
108                 print th($user_cols{$col});
109         }
110         
111         print '<th>Update</th></tr>';
112         
113         for my $row ( sort { $a->usrname cmp $b->usrname } actor::user->search( { super_user => 't' } ) ) {
114
115                 print   "<tr class='row_class".
116                         do {
117                                 if ( !$row->active ) {
118                                         ' deactivated';
119                                 }
120                         }.
121                         "'>\n";
122
123                 print td($row->id); 
124                 print td("<input type='checkbox' name='active_$row' value='t' ".do{if($row->active){"checked"}}.">");
125                 print td("<input type='text' name='usrname_$row' value=".$row->usrname.">");
126                 print td("<input type='password' name='passwd_$row' value=".$row->passwd.">");
127                 print "<td><select name='profile_$row'>";
128                 for my $org ( actor::profile->retrieve_all ) {
129                         print "<option value='".$org->id."' ".do{if($row->profile == $org->id){"selected"}}.">".$org->name."</option>";
130                 }
131                 print "</select></td>";
132                 print td("<input type='text' name='prefix_$row' value=".$row->prefix.">");
133                 print td("<input type='text' name='first_given_name_$row' value=".$row->first_given_name.">");
134                 print td("<input type='text' name='second_given_name_$row' value=".$row->second_given_name.">");
135                 print td("<input type='text' name='family_name_$row' value=".$row->family_name.">");
136                 print td("<input type='text' name='suffix_$row' value=".$row->suffix.">");
137                 print td("<input type='text' name='dob_$row' value=".$row->dob.">");
138                 print td("<input type='text' name='email_$row' value=".$row->email.">");
139                 print td("<input type='text' name='day_phone_$row' value=".$row->day_phone.">");
140                 print td("<input type='text' name='evening_phone_$row' value=".$row->evening_phone.">");
141                 print td("<input type='text' name='other_phone_$row' value=".$row->other_phone.">");
142                 print "<td><select name='home_ou_$row'>";
143                 for my $org ( sort { $a->id <=> $b->id } actor::org_unit->retrieve_all ) {
144                         print "<option value='".$org->id."' ".do{if($row->home_ou == $org->id){"selected"}}.">".do{'&nbsp;&nbsp;'x$org->ou_type->depth}.$org->name."</option>";
145                 }
146                 print "</select></td>";
147                 print "<td><select name='ident_type_$row'>";
148                 for my $org ( config::identification_type->retrieve_all ) {
149                         print "<option value='".$org->id."' ".do{if($row->ident_type == $org->id){"selected"}}.">".$org->name."</option>";
150                 }
151                 print "</select></td>";
152                 print td("<input type='text' name='ident_value_$row' value=".$row->ident_value.">");
153                 print td("<input type='text' name='photo_url_$row' value=".$row->photo_url.">");
154
155                 print   "<td><input type='checkbox' value='$row' name='id'></td></tr>\n";
156         }
157
158         print td(); # id
159         print td("<input type='checkbox' name='active' value='t' checked>");
160         print td("<input type='text' name='usrname'>");
161         print td("<input type='password' name='passwd'>");
162         print "<td><select name='profile'>";
163         for my $org ( actor::profile->retrieve_all ) {
164                 print "<option value='".$org->id."'>".$org->name."</option>";
165         }
166         print "</select></td>";
167         print td("<input type='text' name='prefix'>");
168         print td("<input type='text' name='first_given_name'>");
169         print td("<input type='text' name='second_given_name'>");
170         print td("<input type='text' name='family_name'>");
171         print td("<input type='text' name='suffix'>");
172         print td("<input type='text' name='dob' value='YYYY-MM-DD'>");
173         print td("<input type='text' name='email'>");
174         print td("<input type='text' name='day_phone'>");
175         print td("<input type='text' name='evening_phone'>");
176         print td("<input type='text' name='other_phone'>");
177         print "<td><select name='home_ou'>";
178         for my $row ( sort { $a->id <=> $b->id } actor::org_unit->retrieve_all ) {
179                 print "<option value='".$row->id."'>".do{'&nbsp;&nbsp;'x$row->ou_type->depth}.$row->name."</option>";
180         }
181         print "</select></td>";
182         print "<td><select name='ident_type'>";
183         for my $org ( config::identification_type->retrieve_all ) {
184                 print "<option value='".$org->id."'>".$org->name."</option>";
185         }
186         print "</select></td>";
187         print td("<input type='text' name='ident_value'>");
188         print td("<input type='text' name='photo_url'>");
189         
190         
191         print   "<td></td></tr></table>";
192         print   "<input type='submit' name='action' value='Update Selected'/> | ";
193         print   "<input type='submit' name='action' value='Add New'/>";
194                 "</form><hr/>";
195 }
196
197 print "</body></html>";
198
199