]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/cgi-bin/superuser-setup.cgi
point at the right database
[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=demo-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.new_row_class {
43                         background: grey;
44                 }
45
46                 tr.header_class th {
47                         background-color: lightblue;
48                         border: solid blue 1px;
49                         padding: 2px;
50                 }
51
52         </style>
53 <body style='padding: 25px;'>
54
55 <h1>Superuser Setup</h1>
56 <hr/>
57
58 HEADER
59
60 #-------------------------------------------------------------------------------
61 # setup part
62 #-------------------------------------------------------------------------------
63
64 my %user_cols = (
65         qw/id SysID active Active usrname Username profile UserProfile passwd Password prefix Prefix
66            first_given_name FirstName second_given_name MiddleName family_name LastName
67            suffix Suffix dob Birthdate email Email day_phone DayPhone evening_phone EveningPhone
68            other_phone CellPhone home_ou HomeLib ident_type IdentificationType
69            ident_value Identification_value photo_url PhotoURL/ );
70
71 my @col_display_order = (
72         qw/id active usrname passwd profile prefix first_given_name second_given_name
73            family_name suffix dob email day_phone evening_phone other_phone
74            home_ou ident_type ident_value photo_url/ );
75
76 my @required_cols = ( qw/profile usrname passwd profile ident_type ident_value
77                          first_given_name family_name dob/ );
78
79 #-------------------------------------------------------------------------------
80 # Logic part
81 #-------------------------------------------------------------------------------
82
83 if (my $action = $cgi->param('action')) {
84         if ( $action eq 'Update Selected' ) {
85                 for my $id ( ($cgi->param('id')) ) {
86                         my $u = actor::user->retrieve($id);
87                         for my $col ( @col_display_order ) {
88                                 $u->$col( $cgi->param($col."_$id") );
89                         }
90                         $u->active( 'f' ) unless ($cgi->param("active_$id"));
91                         $u->update;
92                 }
93         } elsif ( $action eq 'Add New' ) {
94                 my $u = actor::user->create(
95                         { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %user_cols }
96                 );
97                 $u->super_user('t');
98                 $u->update;
99         }
100 }
101
102
103 #-------------------------------------------------------------------------------
104 # Form part
105 #-------------------------------------------------------------------------------
106 {
107         #-----------------------------------------------------------------------
108         # User form
109         #-----------------------------------------------------------------------
110         print   "<form method='POST'>".
111                 "<table class='table_class'><tr class='header_class'>\n";
112         
113         for my $col ( @col_display_order ) {
114                 print th($user_cols{$col});
115         }
116         
117         print '<th>Update</th></tr>';
118         
119         for my $row ( sort { $a->usrname cmp $b->usrname } actor::user->search( { super_user => 't' } ) ) {
120
121                 print   "<tr class='row_class".
122                         do {
123                                 if ( !$row->active ) {
124                                         ' deactivated';
125                                 }
126                         }.
127                         "'>\n";
128
129                 print td($row->id); 
130                 print td("<input type='checkbox' name='active_$row' value='t' ".do{if($row->active){"checked"}}.">");
131                 print td("<input type='text' name='usrname_$row' value=".$row->usrname.">");
132                 print td("<input type='password' name='passwd_$row' value=".$row->passwd.">");
133                 print "<td><select name='profile_$row'>";
134                 for my $org ( actor::profile->retrieve_all ) {
135                         print "<option value='".$org->id."' ".do{if($row->profile == $org->id){"selected"}}.">".$org->name."</option>";
136                 }
137                 print "</select></td>";
138                 print td("<input type='text' name='prefix_$row' value=".$row->prefix.">");
139                 print td("<input type='text' name='first_given_name_$row' value=".$row->first_given_name.">");
140                 print td("<input type='text' name='second_given_name_$row' value=".$row->second_given_name.">");
141                 print td("<input type='text' name='family_name_$row' value=".$row->family_name.">");
142                 print td("<input type='text' name='suffix_$row' value=".$row->suffix.">");
143                 print td("<input type='text' name='dob_$row' value=".$row->dob.">");
144                 print td("<input type='text' name='email_$row' value=".$row->email.">");
145                 print td("<input type='text' name='day_phone_$row' value=".$row->day_phone.">");
146                 print td("<input type='text' name='evening_phone_$row' value=".$row->evening_phone.">");
147                 print td("<input type='text' name='other_phone_$row' value=".$row->other_phone.">");
148                 print "<td><select name='home_ou_$row'>";
149                 for my $org ( sort { $a->id <=> $b->id } actor::org_unit->retrieve_all ) {
150                         print "<option value='".$org->id."' ".do{if($row->home_ou == $org->id){"selected"}}.">".do{'&nbsp;&nbsp;'x$org->ou_type->depth}.$org->name."</option>";
151                 }
152                 print "</select></td>";
153                 print "<td><select name='ident_type_$row'>";
154                 for my $org ( config::identification_type->retrieve_all ) {
155                         print "<option value='".$org->id."' ".do{if($row->ident_type == $org->id){"selected"}}.">".$org->name."</option>";
156                 }
157                 print "</select></td>";
158                 print td("<input type='text' name='ident_value_$row' value=".$row->ident_value.">");
159                 print td("<input type='text' name='photo_url_$row' value=".$row->photo_url.">");
160
161                 print   "<td><input type='checkbox' value='$row' name='id'></td></tr>\n";
162         }
163
164         print "<tr class='new_row_class'>";
165         print td(); # id
166         print td("<input type='checkbox' name='active' value='t' checked>");
167         print td("<input type='text' name='usrname'>");
168         print td("<input type='password' name='passwd'>");
169         print "<td><select name='profile'>";
170         for my $org ( actor::profile->retrieve_all ) {
171                 print "<option value='".$org->id."'>".$org->name."</option>";
172         }
173         print "</select></td>";
174         print td("<input type='text' name='prefix'>");
175         print td("<input type='text' name='first_given_name'>");
176         print td("<input type='text' name='second_given_name'>");
177         print td("<input type='text' name='family_name'>");
178         print td("<input type='text' name='suffix'>");
179         print td("<input type='text' name='dob' value='YYYY-MM-DD'>");
180         print td("<input type='text' name='email'>");
181         print td("<input type='text' name='day_phone'>");
182         print td("<input type='text' name='evening_phone'>");
183         print td("<input type='text' name='other_phone'>");
184         print "<td><select name='home_ou'>";
185         for my $row ( sort { $a->id <=> $b->id } actor::org_unit->retrieve_all ) {
186                 print "<option value='".$row->id."'>".do{'&nbsp;&nbsp;'x$row->ou_type->depth}.$row->name."</option>";
187         }
188         print "</select></td>";
189         print "<td><select name='ident_type'>";
190         for my $org ( config::identification_type->retrieve_all ) {
191                 print "<option value='".$org->id."'>".$org->name."</option>";
192         }
193         print "</select></td>";
194         print td("<input type='text' name='ident_value'>");
195         print td("<input type='text' name='photo_url'>");
196         
197         
198         print   "<td></td></tr></table>";
199         print   "<input type='submit' name='action' value='Update Selected'/> | ";
200         print   "<input type='submit' name='action' value='Add New'/>";
201                 "</form><hr/>";
202 }
203
204 print "</body></html>";
205
206