]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/cgi-bin/org_unit_types.cgi
allow circ.reshelving_complete.interval ou setting to override the default reshelving...
[Evergreen.git] / Open-ILS / src / cgi-bin / org_unit_types.cgi
1 #!/usr/bin/perl
2 use strict;
3 # vim:noet:ts=4
4
5 use OpenILS::Application::Storage;
6 use OpenILS::Application::Storage::CDBI;
7
8 # I need to abstract the driver loading away...
9 use OpenILS::Application::Storage::Driver::Pg;
10
11 use CGI qw/:standard start_*/;
12
13 our %config;
14 do '##CONFIG##/live-db-setup.pl';
15
16 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
17 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
18
19 my $cgi = new CGI;
20
21 #-------------------------------------------------------------------------------
22 # HTML part
23 #-------------------------------------------------------------------------------
24
25 print <<HEADER;
26 Content-type: text/html
27
28 <html>
29
30 <head>
31     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
32         <meta http-equiv="Pragma" content="no-cache" />
33         <meta http-equiv="Expires" content="Thu, 01 Dec 2000 16:00:00 GMT" />
34         <style>
35                 table.table_class {
36                         border: dashed lightgrey 1px;
37                         background-color: #EEE;
38                         border-collapse: collapse;
39                 }
40
41                 deactivated {
42                         color: lightgrey;
43                 }
44
45                 tr.row_class td {
46                         border: solid lightgrey 1px;
47                 }
48
49                 tr.new_row_class {
50                         background: grey;
51                 }
52                 
53                 tr.header_class th {
54                         background-color: lightblue;
55                         border: solid blue 1px;
56                         padding: 2px;
57                 }
58
59         </style>
60 <body style='padding: 25px;'>
61
62 <a href="$config{index}">Home</a>
63
64 <h1>Organizational Unit Type Setup</h1>
65 <hr/>
66
67 HEADER
68
69 #-------------------------------------------------------------------------------
70 # setup part
71 #-------------------------------------------------------------------------------
72
73 my %ou_cols = ( qw/id SysID name Name opac_label OpacLabel depth Depth parent ParentType can_have_vols CanHaveVolumes can_have_users CanHaveUsers/ );
74
75 my @col_display_order = ( qw/id name opac_label depth parent can_have_vols can_have_users/ );
76
77 #-------------------------------------------------------------------------------
78 # Logic part
79 #-------------------------------------------------------------------------------
80
81 if (my $action = $cgi->param('action')) {
82         if ( $action eq 'Remove Selected' ) {
83                 for my $id ( ($cgi->param('id')) ) {
84                         actor::org_unit_type->retrieve($id)->delete;
85                 }
86         } elsif ( $action eq 'Update Selected' ) {
87                 for my $id ( ($cgi->param('id')) ) {
88                         my $u = actor::org_unit_type->retrieve($id);
89                         for my $col (@col_display_order) {
90                                 next if ($cgi->param($col."_$id") =~ /Select One/o);
91                                 $u->$col( $cgi->param($col."_$id") );
92                         }
93                         $u->update;
94                 }
95         } elsif ( $action eq 'Add New' ) {
96                 actor::org_unit_type->create( { map {defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } @col_display_order } );
97         }
98 }
99
100
101 #-------------------------------------------------------------------------------
102 # Form part
103 #-------------------------------------------------------------------------------
104 {
105         #-----------------------------------------------------------------------
106         # User form
107         #-----------------------------------------------------------------------
108         print   "<form method='POST'>".
109                 "<table class='table_class'><tr class='header_class'>\n";
110         
111         for my $col ( @col_display_order ) {
112                 print th($ou_cols{$col});
113         }
114         
115         print '<th>Action</th></tr>';
116         
117         for my $row ( sort { $a->depth <=> $b->depth } (actor::org_unit_type->retrieve_all) ) {
118                 print Tr(
119                         td( $row->id() ),
120                         td("<input type='text' name='name_$row' value='". $row->name() ."'>"),
121                         td("<input type='text' name='opac_label_$row' value='". $row->opac_label() ."'>"),
122                         td("<input type='text' size=3 name='depth_$row' value='". $row->depth() ."'>"),
123                         td("<select name='parent_$row'><option>-- Select One --</option>".do{
124                                 my $out = '';
125                                 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
126                                         $out .= "<option value='$type' ".do{
127                                                         if ($row->parent == $type->id) {
128                                                                 "selected";
129                                                         }
130                                                 }.">".$type->name.'</option>'
131                                 }
132                                 $out;
133                                 }."</select>"),
134                         td("<input type='checkbox' name='can_have_vols_$row' value='t' ". do{if($row->can_have_vols){"checked"}} .">"),
135                         td("<input type='checkbox' name='can_have_users_$row' value='t' ". do{if($row->can_have_users){"checked"}} .">"),
136                         td("<input type='checkbox' value='$row' name='id'>"),
137                 );
138         }
139
140         print "<tr class='new_row_class'>",
141                 td(),
142                 td("<input type='text' name='name'>"),
143                 td("<input type='text' name='opac_label'>"),
144                 td("<input type='text' size=3 name='depth'>"),
145                 td("<select name='parent'><option>-- Select One --</option>".do{
146                         my $out = '';
147                         for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
148                                 $out .= "<option value='$type'>".$type->name.'</option>'
149                         }
150                         $out;
151                         }."</select>"),
152                 td("<input type='checkbox' name='can_have_vols' value='t'>"),
153                 td("<input type='checkbox' name='can_have_users' value='t'>"),
154                 td(),
155                 "</tr>";
156         print   "</table>";
157         print   "<input type='submit' name='action' value='Remove Selected'/> | ";
158         print   "<input type='submit' name='action' value='Update Selected'/> | ";
159         print   "<input type='submit' name='action' value='Add New'/></form><hr/>";
160 }
161
162 print "</body></html>";
163
164