making the module name match apache2s requirements
[Evergreen.git] / Open-ILS / src / cgi-bin / circ-rules.cgi
1 #!/usr/bin/perl -w
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 '##CONFIG##/live-db-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                 tr.row_class td {
38                         text-align: right;
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 <a href="$config{index}">Home</a>
56
57 <h1>Configure Circulation Rules</h1>
58 <hr/>
59
60 HEADER
61
62 #-------------------------------------------------------------------------------
63 # setup part
64 #-------------------------------------------------------------------------------
65
66 my %dur_cols = (
67         name            => "Name",
68         extended        => "Extended",
69         normal          => "Normal",
70         shrt            => "Short",
71         max_renewals    => "Max Renewals",
72 );
73
74 my @dur_display_order = ( qw/name normal extended shrt max_renewals/ );
75
76 my %fine_cols = (
77         name                    => "Name",
78         high                    => "High",
79         normal                  => "Normal",
80         low                     => "Low",
81         recurance_interval      => "Interval",
82 );
83
84 my @fine_display_order = ( qw/name recurance_interval normal high low/ );
85
86 my %age_cols = (
87         name    => "Name",
88         age     => "Item Age",
89         prox    => "Holdable Radius",
90 );
91
92 my @age_display_order = ( qw/name age prox/ );
93
94 my %max_fine_cols = (
95         name    => "Name",
96         amount  => "Amount",
97 );
98
99 my @max_fine_display_order = ( qw/name amount/ );
100
101
102 #-------------------------------------------------------------------------------
103 # Logic part
104 #-------------------------------------------------------------------------------
105
106 if (my $action = $cgi->param('action')) {
107         my $form = $cgi->param('rules_form');
108
109         if ($form eq 'duration') {
110                 if ($action eq 'Remove Selected') {
111                         for my $id ( ($cgi->param('remove_me')) ) {
112                                 config::rules::circ_duration->retrieve($id)->delete;
113                         }
114                 } elsif ( $action eq 'Add New' ) {
115                         config::rules::circ_duration->create(
116                                 { map { ($_ => $cgi->param($_)) } keys %dur_cols }
117                         );
118                 }
119         } elsif ($form eq 'recuring_fine') {
120                 if ($action eq 'Remove Selected') {
121                         for my $id ( ($cgi->param('remove_me')) ) {
122                                 config::rules::recuring_fine->retrieve($id)->delete;
123                         }
124                 } elsif ( $action eq 'Add New' ) {
125                         config::rules::recuring_fine->create(
126                                 { map { ($_ => $cgi->param($_)) } keys %fine_cols }
127                         );
128                 }
129         } elsif ($form eq 'max_fine') {
130                 if ($action eq 'Remove Selected') {
131                         for my $id ( ($cgi->param('remove_me')) ) {
132                                 config::rules::max_fine->retrieve($id)->delete;
133                         }
134                 } elsif ( $action eq 'Add New' ) {
135                         config::rules::max_fine->create(
136                                 { map { ($_ => $cgi->param($_)) } keys %max_fine_cols }
137                         );
138                 }
139         } elsif ($form eq 'age_hold') {
140                 if ($action eq 'Remove Selected') {
141                         for my $id ( ($cgi->param('remove_me')) ) {
142                                 config::rules::age_hold_protect->retrieve($id)->delete;
143                         }
144                 } elsif ( $action eq 'Add New' ) {
145                         config::rules::age_hold_protect->create(
146                                 { map { ($_ => $cgi->param($_)) } keys %age_cols }
147                         );
148                 }
149         }
150
151
152 }
153
154
155 #-------------------------------------------------------------------------------
156 # Form part
157 #-------------------------------------------------------------------------------
158 {
159         #-----------------------------------------------------------------------
160         # Duration form
161         #-----------------------------------------------------------------------
162         print   "<form method='POST'>".
163                 "<input type='hidden' name='rules_form' value='duration'>".
164                 "<h2>Circulation Duration</h2>".
165                 "<table class='table_class'><tr class='header_class'>\n";
166         
167         for my $col ( @dur_display_order ) {
168                 print th($dur_cols{$col});
169         }
170         
171         print "<td/>\n";
172         
173         for my $row ( config::rules::circ_duration->retrieve_all ) {
174                 print "</tr><tr class='row_class'>";
175                 for my $col ( @dur_display_order ) {
176                         print td($row->$col);
177                 }
178                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>";
179         }
180         print "</tr><tr class='new_row_class'>\n";
181         
182         for my $col ( @dur_display_order ) {
183                 print td("<input type='text' name='$col'>");
184         }
185         
186         
187         print   "<td/></tr></table>".
188                 "<input type='submit' name='action' value='Add New'/> | ".
189                 "<input type='submit' name='action' value='Remove Selected'/>".
190                 "</form><hr/>";
191 }
192
193 {
194         #-----------------------------------------------------------------------
195         # Recuring Fine form
196         #-----------------------------------------------------------------------
197         print   "<form method='POST'>".
198                 "<input type='hidden' name='rules_form' value='recuring_fine'>".
199                 "<h2>Recuring Fine Levels</h2>".
200                 "<table class='table_class'><tr class='header_class'>\n";
201         
202         for my $col ( @fine_display_order ) {
203                 print th($fine_cols{$col});
204         }
205         
206         print "<td/>\n";
207         
208         for my $row ( config::rules::recuring_fine->retrieve_all ) {
209                 print "</tr><tr class='row_class'>\n";
210                 for my $col ( @fine_display_order ) {
211                         print td($row->$col);
212                 }
213                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>";
214         }
215         
216         print "</tr><tr class='new_row_class'>\n";
217
218         for my $col ( @fine_display_order ) {
219                 print td("<input type='text' name='$col'>");
220         }
221         
222         
223         print   "<td/></tr></table>".
224                 "<input type='submit' name='action' value='Add New'/> | ".
225                 "<input type='submit' name='action' value='Remove Selected'/>".
226                 "</form><hr/>";
227 }
228
229 {
230         #-----------------------------------------------------------------------
231         # Max Fine form
232         #-----------------------------------------------------------------------
233         print   "<form method='POST'>".
234                 "<input type='hidden' name='rules_form' value='max_fine'>".
235                 "<h2>Max Fine Levels</h2>".
236                 "<table class='table_class'><tr class='header_class'>\n";
237         
238         for my $col ( @max_fine_display_order ) {
239                 print th($max_fine_cols{$col});
240         }
241         
242         print "<td/>\n";
243         
244         for my $row ( config::rules::max_fine->retrieve_all ) {
245         print "</tr><tr class='row_class'>\n";
246                 for my $col ( @max_fine_display_order ) {
247                         print td($row->$col);
248                 }
249                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>";
250         }
251         
252         print "</tr><tr class='new_row_class'>\n";
253
254         for my $col ( @max_fine_display_order ) {
255                 print td("<input type='text' name='$col'>");
256         }
257         
258         
259         print   "<td/></tr></table>".
260                 "<input type='submit' name='action' value='Add New'/> | ".
261                 "<input type='submit' name='action' value='Remove Selected'/>".
262                 "</form><hr/>";
263 }
264
265 {
266         #-----------------------------------------------------------------------
267         # Age hold protect form
268         #-----------------------------------------------------------------------
269         print   "<form method='POST'>".
270                 "<input type='hidden' name='rules_form' value='age_hold'>".
271                 "<h2>Item Age Hold Protection</h2>".
272                 "<table class='table_class'><tr class='header_class'>\n";
273         
274         for my $col ( @age_display_order ) {
275                 print th($age_cols{$col});
276         }
277         
278         print "<td/>\n";
279         
280         for my $row ( config::rules::age_hold_protect->retrieve_all ) {
281                 print "</tr><tr class='row_class'>\n";
282                 for my $col ( @age_display_order ) {
283                         print td($row->$col);
284                 }
285                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>";
286         }
287
288         print "</tr><tr class='new_row_class'>\n";
289         
290         for my $col ( @age_display_order ) {
291                 print td("<input type='text' name='$col'>");
292         }
293         
294         
295         print   "<td/></tr></table>".
296                 "<input type='submit' name='action' value='Add New'/> | ".
297                 "<input type='submit' name='action' value='Remove Selected'/>".
298                 "</form><hr/>";
299 }
300
301
302 print "</body></html>";
303
304