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