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
74 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
77 border: dashed lightgrey 1px;
78 background-color: #EEE;
79 border-collapse: collapse;
91 border: solid lightgrey 1px;
95 background-color: lightblue;
96 border: solid blue 1px;
100 /*--------------------------------------------------|
101 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
102 |---------------------------------------------------|
103 | Copyright (c) 2002-2003 Geir Landrö |
104 |--------------------------------------------------*/
107 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
114 vertical-align: middle;
118 text-decoration: none;
120 .dtree a.node, .dtree a.nodeSel {
122 padding: 1px 2px 1px 2px;
124 .dtree a.node:hover, .dtree a.nodeSel:hover {
126 text-decoration: underline;
129 background-color: #c0d2ec;
137 <script language='javascript' src='support/dtree.js'></script>
140 <body style='padding: 25px;'>
142 <a href="$config{index}">Home</a>
144 <h1>User Group Hierarchy Setup</h1>
148 my $uri = $cgi->url(-relative=>1);
151 for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) {
152 my $name = $grp->name;
153 my $desc = $grp->description || $grp->name;
157 <div style="float: left;">
158 <script language='javascript'>
159 var tree = new dTree("tree");
160 tree.add($grp, -1, "$name", "$uri?action=child&id=$grp", "$desc");
166 for my $grp ( permission::grp_tree->search_like( {parent => '%'}, {order_by => 'name'} ) ) {
167 my $name = $grp->name;
168 my $desc = $grp->description || $grp->name;
170 my $parent = $grp->parent;
171 print "\ttree.add($grp, $parent, \"$name\", \"$uri?action=child&id=$grp\", \"$desc\");\n";
175 tree.closeAllChildren($top);
176 document.write(tree.toString());
179 <div style="float:right; width:75%;">
182 #-------------------------------------------------------------------------------
184 #-------------------------------------------------------------------------------
186 if (my $action = $cgi->param('action')) {
187 if ( $action eq 'child' ) {
188 my $id = $cgi->param('id');
190 my $node = permission::grp_tree->retrieve($id);
191 #-----------------------------------------------------------------------
193 #-----------------------------------------------------------------------
195 print "<h2>Edit Group '".$node->name."'</h2>";
196 print "<form method='POST'>".
197 "<table class='table_class'><tr class='header_class'>\n";
205 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
208 th($org_cols{parent}),
209 td("<select name='parent_$node'>".do{
210 my $out = '<option>-- Select One --</option>';
211 for my $org ( sort {$a->id <=> $b->id} permission::grp_tree->retrieve_all) {
212 $out .= "<option value='$org' ".do {
213 if ($node->parent == $org->id) {
215 }}.'>'.$org->name.'</option>'
218 }."</select><input type='hidden' value='$node' name='id'>"),
221 th($org_cols{description}),
222 td("<input type='text' name='description_$node' value=\"". $node->description() ."\">"),
225 th($org_cols{application_perm}),
227 my $out = '<select name="application_perm_'.$node.'"><option value="">-- Select One --</option>';
228 $out .= '<option'.do{
229 " selected='selected'" if ($_->code eq $node->application_perm);
230 }.'>'. $_->code .'</option>' for ( sort {$a->code cmp $b->code} @perms );
236 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
238 print "</table></form><hr/>";
241 print "<h2>Group Permissions</h2>";
243 print "<form method='POST'>".
244 "<table class='table_class'>\n".
245 "<tr class='header_class'><th>Permission</th><th>Select</th><th>At Depth</th><th>Grantable</th></tr>";
247 for my $perm ( sort {$a->code cmp $b->code} @perms ) {
249 my $out = '<select name="depth_'.$perm->id.'"><option value="">-- Select One --</option>';
250 for my $outype ( actor::org_unit_type->retrieve_all ) {
252 $out .= "<option value='".$outype->depth."' ".do{
256 my $setting = permission::grp_perm_map->search(
260 $stuff = "selected " if($setting && $outype->depth == $setting->depth);
261 if($stuff && $setting && $setting->grp != $node->id) {
262 $out =~ s/^<select/<select disabled/o;
265 } while (!$stuff && $grp && ($grp = $grp->parent));
267 }.">".$outype->name."</option>";
270 $out .= "</td><td><input type='checkbox' name='grant_$perm' value='t' ".
275 my $setting = permission::grp_perm_map->search(
279 $stuff = "checked='checked' " if ($setting && $setting->grantable);
281 } while (!$stuff && $grp && ($grp = $grp->parent));
286 print Tr( "<td>".$perm->code."</td><td>".
287 "<input type='checkbox' name='permission_$perm' value='$perm' ".
292 my $setting = permission::grp_perm_map->search(
296 $stuff = "checked " if ($setting);
297 $stuff .= "disabled " if($setting && $setting->grp != $node->id);
299 } while (!$stuff && $grp && ($grp = $grp->parent));
302 "></td><td>$out</td>"
307 print Tr( "<td colspan='3'><input type='hidden' value='$node' name='perms'>",
308 "<input type='submit' name='action' value='Set Permissions'/></td>" );
309 print "</table></form><hr/>";
313 print "<h2>New Child</h2>";
315 print "<form method='POST'>".
316 "<table class='table_class'>\n";
320 td("<input type='text' name='name'>"),
323 th($org_cols{description}),
324 td("<input type='text' name='description'>"),
326 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent'>",
327 "<input type='submit' name='action' value='Add New'/></td>" );
328 print "</table></form><hr/>";
334 print "</div></body></html>";