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