]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/cgi-bin/circ-rules.cgi
adding circulation rule config stuff
[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         short           => "Short",
60         max_renewals    => "Max Renewals",
61 );
62
63 my @dur_display_order = ( qw/name normal extended short 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                                 warn "========>>>  Deleteing $id\n";
102                                 config::rules::circ_duration->retrieve($id)->delete;
103                         }
104                 } elsif ( $action eq 'Add New' ) {
105                         config::rules::circ_duration->create(
106                                 { map { ($_ => $cgi->param($_)) } keys %dur_cols }
107                         );
108                 }
109         } elsif ($form eq 'recuring_fine') {
110                 if ($action eq 'Remove Selected') {
111                         for my $id ( ($cgi->param('remove_me')) ) {
112                                 warn "========>>>  Deleteing $id\n";
113                                 config::rules::recuring_fine->retrieve($id)->delete;
114                         }
115                 } elsif ( $action eq 'Add New' ) {
116                         config::rules::recuring_fine->create(
117                                 { map { ($_ => $cgi->param($_)) } keys %fine_cols }
118                         );
119                 }
120         } elsif ($form eq 'max_fine') {
121                 if ($action eq 'Remove Selected') {
122                         for my $id ( ($cgi->param('remove_me')) ) {
123                                 warn "========>>>  Deleteing $id\n";
124                                 config::rules::max_fine->retrieve($id)->delete;
125                         }
126                 } elsif ( $action eq 'Add New' ) {
127                         config::rules::max_fine->create(
128                                 { map { ($_ => $cgi->param($_)) } keys %max_fine_cols }
129                         );
130                 }
131         } elsif ($form eq 'age_hold') {
132                 if ($action eq 'Remove Selected') {
133                         for my $id ( ($cgi->param('remove_me')) ) {
134                                 warn "========>>>  Deleteing $id\n";
135                                 config::rules::age_hold_protect->retrieve($id)->delete;
136                         }
137                 } elsif ( $action eq 'Add New' ) {
138                         config::rules::age_hold_protect->create(
139                                 { map { ($_ => $cgi->param($_)) } keys %age_cols }
140                         );
141                 }
142         }
143
144
145 }
146
147
148 #-------------------------------------------------------------------------------
149 # Form part
150 #-------------------------------------------------------------------------------
151 {
152         #-----------------------------------------------------------------------
153         # Duration form
154         #-----------------------------------------------------------------------
155         print   "<form method='POST'>".
156                 "<input type='hidden' name='rules_form' value='duration'>".
157                 "<h2>Circulation Duration</h2>".
158                 "<table class='table_class'><tr class='header_class'>\n";
159         
160         for my $col ( @dur_display_order ) {
161                 print th($dur_cols{$col});
162         }
163         
164         print "<td/></tr><tr class='row_class'>\n";
165         
166         for my $row ( config::rules::circ_duration->retrieve_all ) {
167                 for my $col ( @dur_display_order ) {
168                         print td($row->$col);
169                 }
170                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>".
171                         "</tr><tr class='row_class'>\n";
172         }
173         
174         for my $col ( @dur_display_order ) {
175                 print td("<input type='text' name='$col'>");
176         }
177         
178         
179         print   "<td/></tr></table>".
180                 "<input type='submit' name='action' value='Add New'/> | ".
181                 "<input type='submit' name='action' value='Remove Selected'/>".
182                 "</form><hr/>";
183 }
184
185 {
186         #-----------------------------------------------------------------------
187         # Recuring Fine form
188         #-----------------------------------------------------------------------
189         print   "<form method='POST'>".
190                 "<input type='hidden' name='rules_form' value='recuring_fine'>".
191                 "<h2>Recuring Fine Levels</h2>".
192                 "<table class='table_class'><tr class='header_class'>\n";
193         
194         for my $col ( @fine_display_order ) {
195                 print th($fine_cols{$col});
196         }
197         
198         print "<td/></tr><tr class='row_class'>\n";
199         
200         for my $row ( config::rules::recuring_fine->retrieve_all ) {
201                 for my $col ( @fine_display_order ) {
202                         print td($row->$col);
203                 }
204                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>".
205                         "</tr><tr class='row_class'>\n";
206         }
207         
208         for my $col ( @fine_display_order ) {
209                 print td("<input type='text' name='$col'>");
210         }
211         
212         
213         print   "<td/></tr></table>".
214                 "<input type='submit' name='action' value='Add New'/> | ".
215                 "<input type='submit' name='action' value='Remove Selected'/>".
216                 "</form><hr/>";
217 }
218
219 {
220         #-----------------------------------------------------------------------
221         # Max Fine form
222         #-----------------------------------------------------------------------
223         print   "<form method='POST'>".
224                 "<input type='hidden' name='rules_form' value='max_fine'>".
225                 "<h2>Max Fine Levels</h2>".
226                 "<table class='table_class'><tr class='header_class'>\n";
227         
228         for my $col ( @max_fine_display_order ) {
229                 print th($max_fine_cols{$col});
230         }
231         
232         print "<td/></tr><tr class='row_class'>\n";
233         
234         for my $row ( config::rules::max_fine->retrieve_all ) {
235                 for my $col ( @max_fine_display_order ) {
236                         print td($row->$col);
237                 }
238                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>".
239                         "</tr><tr class='row_class'>\n";
240         }
241         
242         for my $col ( @max_fine_display_order ) {
243                 print td("<input type='text' name='$col'>");
244         }
245         
246         
247         print   "<td/></tr></table>".
248                 "<input type='submit' name='action' value='Add New'/> | ".
249                 "<input type='submit' name='action' value='Remove Selected'/>".
250                 "</form><hr/>";
251 }
252
253 {
254         #-----------------------------------------------------------------------
255         # Age hold protect form
256         #-----------------------------------------------------------------------
257         print   "<form method='POST'>".
258                 "<input type='hidden' name='rules_form' value='age_hold'>".
259                 "<h2>Item Age Hold Protection</h2>".
260                 "<table class='table_class'><tr class='header_class'>\n";
261         
262         for my $col ( @age_display_order ) {
263                 print th($age_cols{$col});
264         }
265         
266         print "<td/></tr><tr class='row_class'>\n";
267         
268         for my $row ( config::rules::age_hold_protect->retrieve_all ) {
269                 for my $col ( @age_display_order ) {
270                         if ($col eq 'radius') {
271                                 print td($row->$col->name);
272                         } else {
273                                 print td($row->$col);
274                         }
275                 }
276                 print   "<td><input type='checkbox' value='$row' name='remove_me'</td>".
277                         "</tr><tr class='row_class'>\n";
278         }
279         
280         for my $col ( @age_display_order ) {
281                 if ($col eq 'radius') {
282                         print "<td><select name='$col'>";
283                         for my $radius ( actor::org_unit_type->retrieve_all ) {
284                                 print   "<option value='".$radius->id."'>".
285                                         $radius->name."</option>";
286                         }
287                         print "</select></td>";
288                 } else {
289                         print td("<input type='text' name='$col'>");
290                 }
291         }
292         
293         
294         print   "<td/></tr></table>".
295                 "<input type='submit' name='action' value='Add New'/> | ".
296                 "<input type='submit' name='action' value='Remove Selected'/>".
297                 "</form><hr/>";
298 }
299
300
301 print "</body></html>";
302
303