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_*/;
15 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
16 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
20 #-------------------------------------------------------------------------------
22 #-------------------------------------------------------------------------------
24 my %org_cols = ( qw/id GroupID name Name parent ParentGroup description Description/ );
26 my @col_display_order = ( qw/id name parent description/ );
28 if (my $action = $cgi->param('action')) {
29 if ( $action eq 'Update' ) {
30 for my $id ( ($cgi->param('id')) ) {
31 my $u = permission::grp_tree->retrieve($id);
32 for my $col ( keys %org_cols ) {
33 next if ($cgi->param($col."_$id") =~ /Select One/o);
34 $u->$col( $cgi->param($col."_$id") );
38 } elsif ( $action eq 'Set Permissions' ) {
39 my $grp = permission::grp_tree->retrieve($cgi->param('perms'));
40 my @ids = $cgi->param('permission');
41 for my $perm ( permission::perm_list->retrieve_all ) {
42 if (my $id = $cgi->param('permission_'.$perm->id) ) {
43 my $p = permission::grp_perm_map->search({perm=>$id,grp=>$grp->id})->next;
44 my $d = $cgi->param("depth_$id");
46 $p = permission::grp_perm_map->create({perm=>$id,grp=>$grp->id,depth=>$d});
52 permission::grp_perm_map->search({perm=>$perm->id,grp=>$grp->id})->delete_all;
55 $cgi->param('action'=>'child');
56 } elsif ( $action eq 'Add New' ) {
57 permission::grp_tree->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
61 #-------------------------------------------------------------------------------
63 #-------------------------------------------------------------------------------
66 Content-type: text/html
73 border: dashed lightgrey 1px;
74 background-color: #EEE;
75 border-collapse: collapse;
87 border: solid lightgrey 1px;
91 background-color: lightblue;
92 border: solid blue 1px;
96 /*--------------------------------------------------|
97 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
98 |---------------------------------------------------|
99 | Copyright (c) 2002-2003 Geir Landrö |
100 |--------------------------------------------------*/
103 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
110 vertical-align: middle;
114 text-decoration: none;
116 .dtree a.node, .dtree a.nodeSel {
118 padding: 1px 2px 1px 2px;
120 .dtree a.node:hover, .dtree a.nodeSel:hover {
122 text-decoration: underline;
125 background-color: #c0d2ec;
133 <script language='javascript' src='support/dtree.js'></script>
136 <body style='padding: 25px;'>
138 <a href="$config{index}">Home</a>
140 <h1>User Group Hierarchy Setup</h1>
144 my $uri = $cgi->url(-relative=>1);
147 for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) {
148 my $name = $grp->name;
152 <div style="float: left;">
153 <script language='javascript'>
154 var tree = new dTree("tree");
155 tree.add($grp, -1, "$name", "$uri?action=child&id=$grp", "$name");
161 for my $grp ( permission::grp_tree->search_like( {parent => '%'}, {order_by => 'id'} ) ) {
162 my $name = $grp->name;
164 my $parent = $grp->parent;
165 print "\ttree.add($grp, $parent, \"$name\", \"$uri?action=child&id=$grp\", \"$name\");\n";
169 tree.closeAllChildren($top);
170 document.write(tree.toString());
173 <div style="float:right; width:50%;">
176 #-------------------------------------------------------------------------------
178 #-------------------------------------------------------------------------------
180 if (my $action = $cgi->param('action')) {
181 if ( $action eq 'child' ) {
182 my $id = $cgi->param('id');
184 my $node = permission::grp_tree->retrieve($id);
185 #-----------------------------------------------------------------------
187 #-----------------------------------------------------------------------
189 print "<h2>Edit Group '".$node->name."'</h2>";
190 print "<form method='POST'>".
191 "<table class='table_class'><tr class='header_class'>\n";
199 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
202 th($org_cols{parent}),
203 td("<select name='parent_$node'>".do{
204 my $out = '<option>-- Select One --</option>';
205 for my $org ( sort {$a->id <=> $b->id} permission::grp_tree->retrieve_all) {
206 $out .= "<option value='$org' ".do {
207 if ($node->parent == $org->id) {
209 }}.'>'.$org->name.'</option>'
212 }."</select><input type='hidden' value='$node' name='id'>"),
215 th($org_cols{description}),
216 td("<input type='text' name='description_$node' value=\"". $node->description() ."\">"),
219 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
221 print "</table></form><hr/>";
224 print "<h2>Group Permissions</h2>";
226 print "<form method='POST'>".
227 "<table class='table_class'>\n".
228 "<tr class='header_class'><th>Permission</th><th>Select</th><th>At Depth</th></tr>";
230 for my $perm ( sort {$a->code cmp $b->code} permission::perm_list->retrieve_all ) {
232 my $out = '<select name="depth_'.$perm->id.'"><option value="">-- Select One --</option>';
233 for my $outype ( actor::org_unit_type->retrieve_all ) {
235 $out .= "<option value='".$outype->depth."' ".do{
239 my $setting = permission::grp_perm_map->search(
243 $stuff = "selected " if($setting && $outype->depth == $setting->depth);
244 if($stuff && $setting && $setting->grp != $node->id) {
245 $out =~ s/^<select/<select disabled/o;
248 } while (!$stuff && $grp && ($grp = $grp->parent));
250 }.">".$outype->name."</option>";
254 print Tr( "<td>".$perm->code."</td><td>".
255 "<input type='checkbox' name='permission_$perm' value='$perm' ".
260 my $setting = permission::grp_perm_map->search(
264 $stuff = "checked " if ($setting);
265 $stuff .= "disabled " if($setting && $setting->grp != $node->id);
267 } while (!$stuff && $grp && ($grp = $grp->parent));
270 "></td><td>$out</td>"
275 print Tr( "<td colspan='3'><input type='hidden' value='$node' name='perms'>",
276 "<input type='submit' name='action' value='Set Permissions'/></td>" );
277 print "</table></form><hr/>";
281 print "<h2>New Child</h2>";
283 print "<form method='POST'>".
284 "<table class='table_class'>\n";
288 td("<input type='text' name='name'>"),
291 th($org_cols{description}),
292 td("<input type='text' name='description'>"),
294 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent'>",
295 "<input type='submit' name='action' value='Add New'/></td>" );
296 print "</table></form><hr/>";
302 print "</div></body></html>";