]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/cgi-bin/org_unit_types.cgi
fixed library config; making table headers more readable
[Evergreen.git] / Open-ILS / src / cgi-bin / org_unit_types.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.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>Organizational Unit Type Setup</h1>
56 <hr/>
57
58 HEADER
59
60 #-------------------------------------------------------------------------------
61 # setup part
62 #-------------------------------------------------------------------------------
63
64 my %ou_cols = ( qw/id SysID name Name depth Depth parent ParentType can_have_vols CanHaveVolumes can_have_users CanHaveUsers/ );
65
66 my @col_display_order = ( qw/id name depth parent can_have_vols can_have_users/ );
67
68 #-------------------------------------------------------------------------------
69 # Logic part
70 #-------------------------------------------------------------------------------
71
72 if (my $action = $cgi->param('action')) {
73         if ( $action eq 'Remove Selected' ) {
74                 for my $id ( ($cgi->param('id')) ) {
75                         actor::org_unit_type->retrieve($id)->delete;
76                 }
77         } elsif ( $action eq 'Update Selected' ) {
78                 for my $id ( ($cgi->param('id')) ) {
79                         my $u = actor::org_unit_type->retrieve($id);
80                         for my $col (@col_display_order) {
81                                 $u->$col( $cgi->param($col."_$id") );
82                         }
83                         $u->update;
84                 }
85         } elsif ( $action eq 'Add New' ) {
86                 actor::org_unit_type->create( { map {defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } @col_display_order } );
87         }
88 }
89
90
91 #-------------------------------------------------------------------------------
92 # Form part
93 #-------------------------------------------------------------------------------
94 {
95         #-----------------------------------------------------------------------
96         # User form
97         #-----------------------------------------------------------------------
98         print   "<form method='POST'>".
99                 "<table class='table_class'><tr class='header_class'>\n";
100         
101         for my $col ( @col_display_order ) {
102                 print th($ou_cols{$col});
103         }
104         
105         print '<th>Action</th></tr>';
106         
107         for my $row ( sort { $a->depth <=> $b->depth } (actor::org_unit_type->retrieve_all) ) {
108                 print Tr(
109                         td( $row->id() ),
110                         td("<input type='text' name='name_$row' value='". $row->name() ."'>"),
111                         td("<input type='text' size=3 name='depth_$row' value='". $row->depth() ."'>"),
112                         td("<select name='parent_$row'><option>-- Select One --</option>".do{
113                                 my $out = '';
114                                 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
115                                         $out .= "<option value='$type' ".do{
116                                                         if ($row->parent == $type->id) {
117                                                                 "selected";
118                                                         }
119                                                 }.">".$type->name.'</option>'
120                                 }
121                                 $out;
122                                 }."</select>"),
123                         td("<input type='checkbox' name='can_have_vols_$row' value='t' ". do{if($row->can_have_vols){"checked"}} .">"),
124                         td("<input type='checkbox' name='can_have_users_$row' value='t' ". do{if($row->can_have_users){"checked"}} .">"),
125                         td("<input type='checkbox' value='$row' name='id'>"),
126                 );
127         }
128
129         print "<tr class='new_row_class'>",
130                 td(),
131                 td("<input type='text' name='name'>"),
132                 td("<input type='text' size=3 name='depth'>"),
133                 td("<select name='parent'><option>-- Select One --</option>".do{
134                         my $out = '';
135                         for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
136                                 $out .= "<option value='$type'>".$type->name.'</option>'
137                         }
138                         $out;
139                         }."</select>"),
140                 td("<input type='checkbox' name='can_have_vols' value='t'>"),
141                 td("<input type='checkbox' name='can_have_users' value='t'>"),
142                 td(),
143                 "</tr>";
144         print   "</table>";
145         print   "<input type='submit' name='action' value='Remove Selected'/> | ";
146         print   "<input type='submit' name='action' value='Update Selected'/> | ";
147         print   "<input type='submit' name='action' value='Add New'/></form><hr/>";
148 }
149
150 print "</body></html>";
151
152