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