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