]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/cgi-bin/usr_group-setup.cgi
removing old, unused code
[Evergreen.git] / Open-ILS / src / cgi-bin / usr_group-setup.cgi
1 #!/usr/bin/perl
2 # vim:noet:ts=4
3 use strict;
4
5 use OpenILS::Application::Storage;
6 use OpenILS::Application::Storage::CDBI;
7
8 # I need to abstract the driver loading away...
9 use OpenILS::Application::Storage::Driver::Pg;
10
11 use CGI qw/:standard start_*/;
12
13 our %config;
14 do '##CONFIG##/live-db-setup.pl';
15
16 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
17 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
18
19 my $cgi = new CGI;
20
21 #-------------------------------------------------------------------------------
22 # setup part
23 #-------------------------------------------------------------------------------
24 my @perms = sort { $a->code cmp $b->code } permission::perm_list->retrieve_all;
25
26 my %org_cols = ( qw/id GroupID name Name parent ParentGroup description Description application_perm ApplicationPermission/ );
27
28 my @col_display_order = ( qw/id name parent description application_perm/ );
29
30 if (my $action = $cgi->param('action')) {
31         if ( $action eq 'Update' ) {
32                 for my $id ( ($cgi->param('id')) ) {
33                         my $u = permission::grp_tree->retrieve($id);
34                         for my $col ( keys %org_cols ) {
35                                 next if ($cgi->param($col."_$id") =~ /Select One/o);
36                                 $u->$col( $cgi->param($col."_$id") );
37                         }
38                         $u->update;
39                 }
40         } elsif ( $action eq 'Set Permissions' ) {
41                 my $grp = permission::grp_tree->retrieve($cgi->param('perms'));
42                 my @ids = $cgi->param('permission');
43                 for my $perm ( @perms ) {
44                         if (my $id = $cgi->param('permission_'.$perm->id) ) {
45                                 my $p = permission::grp_perm_map->search({perm=>$id,grp=>$grp->id})->next;
46                                 my $d = $cgi->param("depth_$id");
47                                 my $g = $cgi->param("grant_$id") || 'f';
48                                 if (!$p) {
49                                         $p = permission::grp_perm_map->create({perm=>$id,grp=>$grp->id,depth=>$d,grantable=>$g});
50                                 } else {
51                                         $p->depth( $d );
52                                         $p->grantable( $g );
53                                 }
54                                 $p->update;
55                         } else {
56                                 permission::grp_perm_map->search({perm=>$perm->id,grp=>$grp->id})->delete_all;
57                         }
58                 }
59                 $cgi->param('action'=>'child');
60         } elsif ( $action eq 'Add New' ) {
61                 permission::grp_tree->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
62         }
63 }
64
65 #-------------------------------------------------------------------------------
66 # HTML part
67 #-------------------------------------------------------------------------------
68
69 print <<HEADER;
70 Content-type: text/html
71
72 <html>
73
74 <head>
75     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
76         <meta http-equiv="Pragma" content="no-cache" />
77         <meta http-equiv="Expires" content="Thu, 01 Dec 2000 16:00:00 GMT" />
78         <style>
79                 table.table_class {
80                         border: dashed lightgrey 1px;
81                         background-color: #EEE;
82                         border-collapse: collapse;
83                 }
84
85                 deactivated {
86                         color: lightgrey;
87                 }
88
89                 tr.new_row_class {
90                         background: grey;
91                 }
92
93                 tr.row_class td {
94                         border: solid lightgrey 1px;
95                 }
96                 
97                 tr.header_class th {
98                         background-color: lightblue;
99                         border: solid blue 1px;
100                         padding: 2px;
101                 }
102
103 /*--------------------------------------------------|
104 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
105 |---------------------------------------------------|
106 | Copyright (c) 2002-2003 Geir Landrö               |
107 |--------------------------------------------------*/
108
109 .dtree {
110         font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
111         font-size: 11px;
112         color: #666;
113         white-space: nowrap;
114 }
115 .dtree img {
116         border: 0px;
117         vertical-align: middle;
118 }
119 .dtree a {
120         color: #333;
121         text-decoration: none;
122 }
123 .dtree a.node, .dtree a.nodeSel {
124         white-space: nowrap;
125         padding: 1px 2px 1px 2px;
126 }
127 .dtree a.node:hover, .dtree a.nodeSel:hover {
128         color: #333;
129         text-decoration: underline;
130 }
131 .dtree a.nodeSel {
132         background-color: #c0d2ec;
133 }
134 .dtree .clip {
135         overflow: hidden;
136 }
137
138
139         </style>
140         <script language='javascript' src='support/dtree.js'></script>
141 </head>
142
143 <body style='padding: 25px;'>
144
145 <a href="$config{index}">Home</a>
146
147 <h1>User Group Hierarchy Setup</h1>
148 <hr/>
149 HEADER
150
151 my $uri = $cgi->url(-relative=>1);
152
153 my $top;
154 for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) {
155         my $name = $grp->name;
156         my $desc = $grp->description || $grp->name;
157         $top = $grp->id;
158         $name =~ s/'/\\'/og;
159         print <<"       HEADER";
160 <div style="float: left;">
161         <script language='javascript'>
162         var tree = new dTree("tree");
163         tree.add($grp, -1, "$name", "$uri?action=child&id=$grp", "$desc");
164         HEADER
165         $top = $grp->id;
166         last;
167 }
168
169 for my $grp ( permission::grp_tree->search_like( {parent => '%'}, {order_by => 'name'} ) ) {
170         my $name = $grp->name;
171         my $desc = $grp->description || $grp->name;
172         $name =~ s/'/\\'/og;
173         my $parent = $grp->parent;
174         print "\ttree.add($grp, $parent, \"$name\", \"$uri?action=child&id=$grp\", \"$desc\");\n";
175 }
176
177 print <<HEADER;
178         tree.closeAllChildren($top);
179         document.write(tree.toString());
180         </script>
181 </div>
182 <div style="float:right; width:75%;">
183 HEADER
184
185 #-------------------------------------------------------------------------------
186 # Logic part
187 #-------------------------------------------------------------------------------
188
189 if (my $action = $cgi->param('action')) {
190         if ( $action eq 'child' ) {
191                 my $id = $cgi->param('id');
192                 if ($id) {
193                         my $node = permission::grp_tree->retrieve($id);
194                         #-----------------------------------------------------------------------
195                         # child form
196                         #-----------------------------------------------------------------------
197
198                         print "<h2>Edit Group '".$node->name."'</h2>";
199                         print   "<form method='POST'>".
200                                 "<table class='table_class'><tr class='header_class'>\n";
201         
202                         print Tr(
203                                 th($org_cols{id}),
204                                 td( $node->id() ),
205                         );
206                         print Tr(
207                                 th($org_cols{name}),
208                                 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
209                         );
210                         print Tr(
211                                 th($org_cols{parent}),
212                                 td("<select name='parent_$node'>".do{
213                                                 my $out = '<option>-- Select One --</option>';
214                                                 for my $org ( sort {$a->id <=> $b->id} permission::grp_tree->retrieve_all) {
215                                                         $out .= "<option value='$org' ".do {
216                                                                 if ($node->parent == $org->id) {
217                                                                         "selected";
218                                                                 }}.'>'.$org->name.'</option>'
219                                                 }
220                                                 $out;
221                                         }."</select><input type='hidden' value='$node' name='id'>"),
222                         );
223                         print Tr(
224                                 th($org_cols{description}),
225                                 td("<input type='text' name='description_$node' value=\"". $node->description() ."\">"),
226                         );
227                         print Tr(
228                                 th($org_cols{application_perm}),
229                                 "<td>".do {
230                                         my $out = '<select name="application_perm_'.$node.'"><option value="">-- Select One --</option>';
231                                         $out .= '<option'.do{
232                                                         " selected='selected'" if ($_->code eq $node->application_perm);
233                                                 }.'>'. $_->code .'</option>' for ( sort {$a->code cmp $b->code} @perms ); 
234                                         $out .= '</select>';
235                                         $out;
236                                 }."</td>"
237                         );
238
239                         print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
240
241                         print   "</table></form><hr/>";
242
243
244                         print "<h2>Group Permissions</h2>";
245
246                         print   "<form method='POST'>".
247                                 "<table class='table_class'>\n".
248                                 "<tr class='header_class'><th>Permission</th><th>Select</th><th>At Depth</th><th>Grantable</th></tr>";
249
250                         for my $perm ( sort {$a->code cmp $b->code} @perms ) {
251                                 my $grp = $node;
252                                 my $out = '<select name="depth_'.$perm->id.'"><option value="">-- Select One --</option>';
253                                 for my $outype ( actor::org_unit_type->retrieve_all ) {
254                                         my $grp = $node;
255                                         $out .= "<option value='".$outype->depth."' ".do{
256                                                 my $stuff = '';
257                                                 do {
258                                                         if ($grp) {
259                                                                 my $setting = permission::grp_perm_map->search(
260                                                                                 { grp  => $grp->id,
261                                                                                   perm => $perm->id }
262                                                                 )->next;
263                                                                 $stuff = "selected " if($setting && $outype->depth == $setting->depth);
264                                                                 if($stuff && $setting && $setting->grp != $node->id) {
265                                                                         $out =~ s/^<select/<select disabled/o;
266                                                                 }
267                                                         }
268                                                 } while (!$stuff && $grp && ($grp = $grp->parent));
269                                                 $stuff;
270                                         }.">".$outype->name."</option>";
271                                 }
272                                 $out .= "</select>";
273                                 $out .= "</td><td><input type='checkbox' name='grant_$perm' value='t' ".
274                                           do{
275                                                 my $stuff = '';
276                                                 do {
277                                                         if ($grp) {
278                                                                 my $setting = permission::grp_perm_map->search(
279                                                                                 { grp  => $grp->id,
280                                                                                   perm => $perm->id }
281                                                                 )->next;
282                                                                 $stuff = "checked='checked' " if ($setting && $setting->grantable);
283                                                         }
284                                                 } while (!$stuff && $grp && ($grp = $grp->parent));
285                                                 $stuff;
286                                           }.">";
287
288                                 $grp = $node;
289                                 print Tr( "<td>".$perm->code."</td><td>".
290                                           "<input type='checkbox' name='permission_$perm' value='$perm' ".
291                                           do{
292                                                 my $stuff = '';
293                                                 do {
294                                                         if ($grp) {
295                                                                 my $setting = permission::grp_perm_map->search(
296                                                                                 { grp  => $grp->id,
297                                                                                   perm => $perm->id }
298                                                                 )->next;
299                                                                 $stuff = "checked " if ($setting);
300                                                                 $stuff .= "disabled " if($setting && $setting->grp != $node->id);
301                                                         }
302                                                 } while (!$stuff && $grp && ($grp = $grp->parent));
303                                                 $stuff;
304                                           }.
305                                           "></td><td>$out</td>"
306
307                                 );
308                         }
309                         
310                         print Tr( "<td colspan='3'><input type='hidden' value='$node' name='perms'>",
311                                   "<input type='submit' name='action' value='Set Permissions'/></td>" );
312                         print   "</table></form><hr/>";
313
314
315
316                         print "<h2>New Child</h2>";
317         
318                         print   "<form method='POST'>".
319                                 "<table class='table_class'>\n";
320
321                         print Tr(
322                                 th($org_cols{name}),
323                                 td("<input type='text' name='name'>"),
324                         );
325                         print Tr(
326                                 th($org_cols{description}),
327                                 td("<input type='text' name='description'>"),
328                         );
329                         print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent'>",
330                                   "<input type='submit' name='action' value='Add New'/></td>" );
331                         print   "</table></form><hr/>";
332
333                 }
334         }
335 }
336         
337 print "</div></body></html>";
338
339