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