]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/cgi-bin/org_unit_types.cgi
adjusting datasource include
[working/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 our %config;
13 do 'setup.pl';
14
15 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
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>Organizational Unit Type Setup</h1>
61 <hr/>
62
63 HEADER
64
65 #-------------------------------------------------------------------------------
66 # setup part
67 #-------------------------------------------------------------------------------
68
69 my %ou_cols = ( qw/id SysID name Name opac_label OpacLabel depth Depth parent ParentType can_have_vols CanHaveVolumes can_have_users CanHaveUsers/ );
70
71 my @col_display_order = ( qw/id name opac_label depth parent can_have_vols can_have_users/ );
72
73 #-------------------------------------------------------------------------------
74 # Logic part
75 #-------------------------------------------------------------------------------
76
77 if (my $action = $cgi->param('action')) {
78         if ( $action eq 'Remove Selected' ) {
79                 for my $id ( ($cgi->param('id')) ) {
80                         actor::org_unit_type->retrieve($id)->delete;
81                 }
82         } elsif ( $action eq 'Update Selected' ) {
83                 for my $id ( ($cgi->param('id')) ) {
84                         my $u = actor::org_unit_type->retrieve($id);
85                         for my $col (@col_display_order) {
86                                 next if ($cgi->param($col."_$id") =~ /Select One/o);
87                                 $u->$col( $cgi->param($col."_$id") );
88                         }
89                         $u->update;
90                 }
91         } elsif ( $action eq 'Add New' ) {
92                 actor::org_unit_type->create( { map {defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } @col_display_order } );
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($ou_cols{$col});
109         }
110         
111         print '<th>Action</th></tr>';
112         
113         for my $row ( sort { $a->depth <=> $b->depth } (actor::org_unit_type->retrieve_all) ) {
114                 print Tr(
115                         td( $row->id() ),
116                         td("<input type='text' name='name_$row' value='". $row->name() ."'>"),
117                         td("<input type='text' name='opac_label_$row' value='". $row->opac_label() ."'>"),
118                         td("<input type='text' size=3 name='depth_$row' value='". $row->depth() ."'>"),
119                         td("<select name='parent_$row'><option>-- Select One --</option>".do{
120                                 my $out = '';
121                                 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
122                                         $out .= "<option value='$type' ".do{
123                                                         if ($row->parent == $type->id) {
124                                                                 "selected";
125                                                         }
126                                                 }.">".$type->name.'</option>'
127                                 }
128                                 $out;
129                                 }."</select>"),
130                         td("<input type='checkbox' name='can_have_vols_$row' value='t' ". do{if($row->can_have_vols){"checked"}} .">"),
131                         td("<input type='checkbox' name='can_have_users_$row' value='t' ". do{if($row->can_have_users){"checked"}} .">"),
132                         td("<input type='checkbox' value='$row' name='id'>"),
133                 );
134         }
135
136         print "<tr class='new_row_class'>",
137                 td(),
138                 td("<input type='text' name='name'>"),
139                 td("<input type='text' name='opac_label'>"),
140                 td("<input type='text' size=3 name='depth'>"),
141                 td("<select name='parent'><option>-- Select One --</option>".do{
142                         my $out = '';
143                         for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
144                                 $out .= "<option value='$type'>".$type->name.'</option>'
145                         }
146                         $out;
147                         }."</select>"),
148                 td("<input type='checkbox' name='can_have_vols' value='t'>"),
149                 td("<input type='checkbox' name='can_have_users' value='t'>"),
150                 td(),
151                 "</tr>";
152         print   "</table>";
153         print   "<input type='submit' name='action' value='Remove Selected'/> | ";
154         print   "<input type='submit' name='action' value='Update Selected'/> | ";
155         print   "<input type='submit' name='action' value='Add New'/></form><hr/>";
156 }
157
158 print "</body></html>";
159
160