5 use OpenILS::Application::Storage;
6 use OpenILS::Application::Storage::CDBI;
8 # I need to abstract the driver loading away...
9 use OpenILS::Application::Storage::Driver::Pg;
11 use CGI qw/:standard start_*/;
14 do '##CONFIG##/live-db-setup.pl';
16 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
17 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
21 #-------------------------------------------------------------------------------
23 #-------------------------------------------------------------------------------
24 my @perms = sort { $a->code cmp $b->code } permission::perm_list->retrieve_all;
26 my %org_cols = ( qw/id GroupID name Name parent ParentGroup description Description application_perm ApplicationPermission/ );
28 my @col_display_order = ( qw/id name parent description application_perm/ );
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") );
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';
49 $p = permission::grp_perm_map->create({perm=>$id,grp=>$grp->id,depth=>$d,grantable=>$g});
56 permission::grp_perm_map->search({perm=>$perm->id,grp=>$grp->id})->delete_all;
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 } );
65 #-------------------------------------------------------------------------------
67 #-------------------------------------------------------------------------------
70 Content-type: text/html
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" />
80 border: dashed lightgrey 1px;
81 background-color: #EEE;
82 border-collapse: collapse;
94 border: solid lightgrey 1px;
98 background-color: lightblue;
99 border: solid blue 1px;
103 /*--------------------------------------------------|
104 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
105 |---------------------------------------------------|
106 | Copyright (c) 2002-2003 Geir Landrö |
107 |--------------------------------------------------*/
110 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
117 vertical-align: middle;
121 text-decoration: none;
123 .dtree a.node, .dtree a.nodeSel {
125 padding: 1px 2px 1px 2px;
127 .dtree a.node:hover, .dtree a.nodeSel:hover {
129 text-decoration: underline;
132 background-color: #c0d2ec;
140 <script language='javascript' src='support/dtree.js'></script>
143 <body style='padding: 25px;'>
145 <a href="$config{index}">Home</a>
147 <h1>User Group Hierarchy Setup</h1>
151 my $uri = $cgi->url(-relative=>1);
154 for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) {
155 my $name = $grp->name;
156 my $desc = $grp->description || $grp->name;
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");
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;
173 my $parent = $grp->parent;
174 print "\ttree.add($grp, $parent, \"$name\", \"$uri?action=child&id=$grp\", \"$desc\");\n";
178 tree.closeAllChildren($top);
179 document.write(tree.toString());
182 <div style="float:right; width:75%;">
185 #-------------------------------------------------------------------------------
187 #-------------------------------------------------------------------------------
189 if (my $action = $cgi->param('action')) {
190 if ( $action eq 'child' ) {
191 my $id = $cgi->param('id');
193 my $node = permission::grp_tree->retrieve($id);
194 #-----------------------------------------------------------------------
196 #-----------------------------------------------------------------------
198 print "<h2>Edit Group '".$node->name."'</h2>";
199 print "<form method='POST'>".
200 "<table class='table_class'><tr class='header_class'>\n";
208 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
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) {
218 }}.'>'.$org->name.'</option>'
221 }."</select><input type='hidden' value='$node' name='id'>"),
224 th($org_cols{description}),
225 td("<input type='text' name='description_$node' value=\"". $node->description() ."\">"),
228 th($org_cols{application_perm}),
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 );
239 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
241 print "</table></form><hr/>";
244 print "<h2>Group Permissions</h2>";
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>";
250 for my $perm ( sort {$a->code cmp $b->code} @perms ) {
252 my $out = '<select name="depth_'.$perm->id.'"><option value="">-- Select One --</option>';
253 for my $outype ( actor::org_unit_type->retrieve_all ) {
255 $out .= "<option value='".$outype->depth."' ".do{
259 my $setting = permission::grp_perm_map->search(
263 $stuff = "selected " if($setting && $outype->depth == $setting->depth);
264 if($stuff && $setting && $setting->grp != $node->id) {
265 $out =~ s/^<select/<select disabled/o;
268 } while (!$stuff && $grp && ($grp = $grp->parent));
270 }.">".$outype->name."</option>";
273 $out .= "</td><td><input type='checkbox' name='grant_$perm' value='t' ".
278 my $setting = permission::grp_perm_map->search(
282 $stuff = "checked='checked' " if ($setting && $setting->grantable);
284 } while (!$stuff && $grp && ($grp = $grp->parent));
289 print Tr( "<td>".$perm->code."</td><td>".
290 "<input type='checkbox' name='permission_$perm' value='$perm' ".
295 my $setting = permission::grp_perm_map->search(
299 $stuff = "checked " if ($setting);
300 $stuff .= "disabled " if($setting && $setting->grp != $node->id);
302 } while (!$stuff && $grp && ($grp = $grp->parent));
305 "></td><td>$out</td>"
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/>";
316 print "<h2>New Child</h2>";
318 print "<form method='POST'>".
319 "<table class='table_class'>\n";
323 td("<input type='text' name='name'>"),
326 th($org_cols{description}),
327 td("<input type='text' name='description'>"),
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/>";
337 print "</div></body></html>";