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