]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/cgi-bin/user-profiles.cgi
point at the right database
[Evergreen.git] / Open-ILS / src / cgi-bin / user-profiles.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 OpenILS::Application::Storage::CDBI->connection('dbi:Pg:host=10.0.0.2;dbname=demo-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                 deactivated {
35                         color: lightgrey;
36                 }
37
38                 tr.row_class td {
39                         border: solid lightgrey 1px;
40                 }
41                 
42                 tr.new_row_class {
43                         background: grey;
44                 }
45
46                 tr.header_class th {
47                         background-color: lightblue;
48                         border: solid blue 1px;
49                         padding: 2px;
50                 }
51
52         </style>
53 <body style='padding: 25px;'>
54
55 <h1>User Profile Setup</h1>
56 <hr/>
57
58 HEADER
59
60 #-------------------------------------------------------------------------------
61 # setup part
62 #-------------------------------------------------------------------------------
63
64 my %profile_cols = ( qw/id SysID name Name/ );
65
66 my @col_display_order = ( qw/id name/ );
67
68 #-------------------------------------------------------------------------------
69 # Logic part
70 #-------------------------------------------------------------------------------
71
72 if (my $action = $cgi->param('action')) {
73         if ( $action eq 'Remove Selected' ) {
74                 for my $id ( ($cgi->param('id')) ) {
75                         actor::profile->retrieve($id)->delete;
76                 }
77         } elsif ( $action eq 'Update Selected' ) {
78                 for my $id ( ($cgi->param('id')) ) {
79                         my $u = actor::profile->retrieve($id);
80                         $u->name( $cgi->param("name_$id") );
81                         $u->update;
82                 }
83         } elsif ( $action eq 'Add New' ) {
84                 actor::profile->create( { name => $cgi->param("name") } );
85         }
86 }
87
88
89 #-------------------------------------------------------------------------------
90 # Form part
91 #-------------------------------------------------------------------------------
92 {
93         #-----------------------------------------------------------------------
94         # User form
95         #-----------------------------------------------------------------------
96         print   "<form method='POST'>".
97                 "<table class='table_class'><tr class='header_class'>\n";
98         
99         for my $col ( @col_display_order ) {
100                 print th($profile_cols{$col});
101         }
102         
103         print '<th>Action</th></tr>';
104         
105         for my $row ( sort { $a->name cmp $b->name } (actor::profile->retrieve_all) ) {
106                 print Tr(
107                         td( $row->id() ),
108                         td("<input type='text' name='name_$row' value='". $row->name() ."'>"),
109                         td("<input type='checkbox' value='$row' name='id'>"),
110                 );
111         }
112
113         print "<tr class='new_row_class'>",
114                 td(),
115                 td("<input type='text' name='name'>"),
116                 td(),
117                 "</tr>";
118         print   "</table>";
119         print   "<input type='submit' name='action' value='Remove Selected'/> | ";
120         print   "<input type='submit' name='action' value='Update Selected'/> | ";
121         print   "<input type='submit' name='action' value='Add New'/></form><hr/>";
122 }
123
124 print "</body></html>";
125
126