]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/cgi-bin/copy_statuses.cgi
7d6cac919d4f6922e732bb15504ceb907ff7f706
[Evergreen.git] / Open-ILS / src / cgi-bin / copy_statuses.cgi
1 #!/usr/bin/perl
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 our %config;
12 do 'setup.pl';
13
14 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
15 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
16
17 my $cgi = new CGI;
18
19 #-------------------------------------------------------------------------------
20 # HTML part
21 #-------------------------------------------------------------------------------
22
23 print <<HEADER;
24 Content-type: text/html
25
26 <html>
27
28 <head>
29         <style>
30                 table.table_class {
31                         border: dashed lightgrey 1px;
32                         background-color: #EEE;
33                         border-collapse: collapse;
34                 }
35
36                 deactivated {
37                         color: lightgrey;
38                 }
39
40                 tr.row_class td {
41                         border: solid lightgrey 1px;
42                 }
43
44                 tr.new_row_class {
45                         background: grey;
46                 }
47                 
48                 tr.header_class th {
49                         background-color: lightblue;
50                         border: solid blue 1px;
51                         padding: 2px;
52                 }
53
54         </style>
55 <body style='padding: 25px;'>
56
57 <a href="$config{index}">Home</a>
58
59 <h1>Copy Status Setup</h1>
60 <hr/>
61
62 HEADER
63
64 #-------------------------------------------------------------------------------
65 # setup part
66 #-------------------------------------------------------------------------------
67
68 my %cs_cols = ( qw/id SysID name Name holdable Unholdable/ );
69
70 my @col_display_order = ( qw/id name holdable/ );
71
72 #-------------------------------------------------------------------------------
73 # Logic part
74 #-------------------------------------------------------------------------------
75
76 if (my $action = $cgi->param('action')) {
77         if ( $action eq 'Remove Selected' ) {
78                 for my $id ( ($cgi->param('id')) ) {
79                         next unless ($id > 99);
80                         config::copy_status->retrieve($id)->delete;
81                 }
82         } elsif ( $action eq 'Update Selected' ) {
83                 for my $id ( ($cgi->param('id')) ) {
84                         my $u = config::copy_status->retrieve($id);
85                         $u->name( $cgi->param("name_$id") );
86                         $u->holdable( $cgi->param("holdable_$id") );
87                         $u->update;
88                 }
89         } elsif ( $action eq 'Add New' ) {
90                 config::copy_status->create( { name => $cgi->param("name") } );
91         }
92 }
93
94
95 #-------------------------------------------------------------------------------
96 # Form part
97 #-------------------------------------------------------------------------------
98 {
99         #-----------------------------------------------------------------------
100         # User form
101         #-----------------------------------------------------------------------
102         print   "<form method='POST'>".
103                 "<table class='table_class'><tr class='header_class'>\n";
104         
105         for my $col ( @col_display_order ) {
106                 print th($cs_cols{$col});
107         }
108         
109         print '<th>Action</th></tr>';
110         
111         for my $row ( sort { $a->name cmp $b->name } (config::copy_status->retrieve_all) ) {
112                 print Tr(
113                         td( $row->id() ),
114                         td("<input type='text' name='name_$row' value='". $row->name() ."'>"),
115                         td("<input type='checkbox' name='holdable_$row' value='f'". do {'checked' unless $row->holdable()} .">"),
116                         td("<input type='checkbox' value='$row' name='id'>"),
117                 );
118         }
119
120         print "<tr class='new_row_class'>",
121                 td(),
122                 td("<input type='text' name='name'>"),
123                 td("<input type='checkbox' name='holdable' value='f'>"),
124                 td(),
125                 "</tr>";
126
127         print   "</table>";
128         print   "<input type='submit' name='action' value='Remove Selected'/> | ";
129         print   "<input type='submit' name='action' value='Update Selected'/> | ";
130         print   "<input type='submit' name='action' value='Add New'/></form><hr/>";
131 }
132
133 print "</body></html>";
134
135