4 use OpenILS::Application::Storage;
5 use OpenILS::Application::Storage::CDBI;
7 # I need to abstract the driver loading away...
8 use OpenILS::Application::Storage::Driver::Pg;
10 use CGI qw/:standard start_*/;
13 do '##CONFIG##/live-db-setup.pl';
15 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
16 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
20 #-------------------------------------------------------------------------------
22 #-------------------------------------------------------------------------------
23 my @perms = sort { $a->code cmp $b->code } permission::perm_list->retrieve_all;
25 my %org_cols = ( qw/id GroupID name Name parent ParentGroup description Description application_perm ApplicationPermission/ );
27 my @col_display_order = ( qw/id name parent description application_perm/ );
29 if (my $action = $cgi->param('action')) {
30 if ( $action eq 'Update' ) {
31 for my $id ( ($cgi->param('id')) ) {
32 my $u = permission::grp_tree->retrieve($id);
33 for my $col ( keys %org_cols ) {
34 next if ($cgi->param($col."_$id") =~ /Select One/o);
35 $u->$col( $cgi->param($col."_$id") );
39 } elsif ( $action eq 'Set Permissions' ) {
40 my $grp = permission::grp_tree->retrieve($cgi->param('perms'));
41 my @ids = $cgi->param('permission');
42 for my $perm ( @perms ) {
43 if (my $id = $cgi->param('permission_'.$perm->id) ) {
44 my $p = permission::grp_perm_map->search({perm=>$id,grp=>$grp->id})->next;
45 my $d = $cgi->param("depth_$id");
46 my $g = $cgi->param("grant_$id") || 'f';
48 $p = permission::grp_perm_map->create({perm=>$id,grp=>$grp->id,depth=>$d,grantable=>$g});
55 permission::grp_perm_map->search({perm=>$perm->id,grp=>$grp->id})->delete_all;
58 $cgi->param('action'=>'child');
59 } elsif ( $action eq 'Add New' ) {
60 permission::grp_tree->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
64 #-------------------------------------------------------------------------------
66 #-------------------------------------------------------------------------------
69 Content-type: text/html
76 border: dashed lightgrey 1px;
77 background-color: #EEE;
78 border-collapse: collapse;
90 border: solid lightgrey 1px;
94 background-color: lightblue;
95 border: solid blue 1px;
99 /*--------------------------------------------------|
100 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
101 |---------------------------------------------------|
102 | Copyright (c) 2002-2003 Geir Landrö |
103 |--------------------------------------------------*/
106 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
113 vertical-align: middle;
117 text-decoration: none;
119 .dtree a.node, .dtree a.nodeSel {
121 padding: 1px 2px 1px 2px;
123 .dtree a.node:hover, .dtree a.nodeSel:hover {
125 text-decoration: underline;
128 background-color: #c0d2ec;
136 <script language='javascript' src='support/dtree.js'></script>
139 <body style='padding: 25px;'>
141 <a href="$config{index}">Home</a>
143 <h1>User Group Hierarchy Setup</h1>
147 my $uri = $cgi->url(-relative=>1);
150 for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) {
151 my $name = $grp->name;
152 my $desc = $grp->description || $grp->name;
156 <div style="float: left;">
157 <script language='javascript'>
158 var tree = new dTree("tree");
159 tree.add($grp, -1, "$name", "$uri?action=child&id=$grp", "$desc");
165 for my $grp ( permission::grp_tree->search_like( {parent => '%'}, {order_by => 'name'} ) ) {
166 my $name = $grp->name;
167 my $desc = $grp->description || $grp->name;
169 my $parent = $grp->parent;
170 print "\ttree.add($grp, $parent, \"$name\", \"$uri?action=child&id=$grp\", \"$desc\");\n";
174 tree.closeAllChildren($top);
175 document.write(tree.toString());
178 <div style="float:right; width:75%;">
181 #-------------------------------------------------------------------------------
183 #-------------------------------------------------------------------------------
185 if (my $action = $cgi->param('action')) {
186 if ( $action eq 'child' ) {
187 my $id = $cgi->param('id');
189 my $node = permission::grp_tree->retrieve($id);
190 #-----------------------------------------------------------------------
192 #-----------------------------------------------------------------------
194 print "<h2>Edit Group '".$node->name."'</h2>";
195 print "<form method='POST'>".
196 "<table class='table_class'><tr class='header_class'>\n";
204 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
207 th($org_cols{parent}),
208 td("<select name='parent_$node'>".do{
209 my $out = '<option>-- Select One --</option>';
210 for my $org ( sort {$a->id <=> $b->id} permission::grp_tree->retrieve_all) {
211 $out .= "<option value='$org' ".do {
212 if ($node->parent == $org->id) {
214 }}.'>'.$org->name.'</option>'
217 }."</select><input type='hidden' value='$node' name='id'>"),
220 th($org_cols{description}),
221 td("<input type='text' name='description_$node' value=\"". $node->description() ."\">"),
224 th($org_cols{application_perm}),
226 my $out = '<select name="application_perm_'.$node.'"><option value="">-- Select One --</option>';
227 $out .= '<option'.do{
228 " selected='selected'" if ($_->code eq $node->application_perm);
229 }.'>'. $_->code .'</option>' for ( sort {$a->code cmp $b->code} @perms );
235 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
237 print "</table></form><hr/>";
240 print "<h2>Group Permissions</h2>";
242 print "<form method='POST'>".
243 "<table class='table_class'>\n".
244 "<tr class='header_class'><th>Permission</th><th>Select</th><th>At Depth</th><th>Grantable</th></tr>";
246 for my $perm ( sort {$a->code cmp $b->code} @perms ) {
248 my $out = '<select name="depth_'.$perm->id.'"><option value="">-- Select One --</option>';
249 for my $outype ( actor::org_unit_type->retrieve_all ) {
251 $out .= "<option value='".$outype->depth."' ".do{
255 my $setting = permission::grp_perm_map->search(
259 $stuff = "selected " if($setting && $outype->depth == $setting->depth);
260 if($stuff && $setting && $setting->grp != $node->id) {
261 $out =~ s/^<select/<select disabled/o;
264 } while (!$stuff && $grp && ($grp = $grp->parent));
266 }.">".$outype->name."</option>";
269 $out .= "</td><td><input type='checkbox' name='grant_$perm' value='t' ".
274 my $setting = permission::grp_perm_map->search(
278 $stuff = "checked='checked' " if ($setting && $setting->grantable);
280 } while (!$stuff && $grp && ($grp = $grp->parent));
285 print Tr( "<td>".$perm->code."</td><td>".
286 "<input type='checkbox' name='permission_$perm' value='$perm' ".
291 my $setting = permission::grp_perm_map->search(
295 $stuff = "checked " if ($setting);
296 $stuff .= "disabled " if($setting && $setting->grp != $node->id);
298 } while (!$stuff && $grp && ($grp = $grp->parent));
301 "></td><td>$out</td>"
306 print Tr( "<td colspan='3'><input type='hidden' value='$node' name='perms'>",
307 "<input type='submit' name='action' value='Set Permissions'/></td>" );
308 print "</table></form><hr/>";
312 print "<h2>New Child</h2>";
314 print "<form method='POST'>".
315 "<table class='table_class'>\n";
319 td("<input type='text' name='name'>"),
322 th($org_cols{description}),
323 td("<input type='text' name='description'>"),
325 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent'>",
326 "<input type='submit' name='action' value='Add New'/></td>" );
327 print "</table></form><hr/>";
333 print "</div></body></html>";