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 #-------------------------------------------------------------------------------
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");
45 my $g = $cgi->param("grant_$id") || 'f';
47 $p = permission::grp_perm_map->create({perm=>$id,grp=>$grp->id,depth=>$d,grantable=>$g});
54 permission::grp_perm_map->search({perm=>$perm->id,grp=>$grp->id})->delete_all;
57 $cgi->param('action'=>'child');
58 } elsif ( $action eq 'Add New' ) {
59 permission::grp_tree->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
63 #-------------------------------------------------------------------------------
65 #-------------------------------------------------------------------------------
68 Content-type: text/html
75 border: dashed lightgrey 1px;
76 background-color: #EEE;
77 border-collapse: collapse;
89 border: solid lightgrey 1px;
93 background-color: lightblue;
94 border: solid blue 1px;
98 /*--------------------------------------------------|
99 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
100 |---------------------------------------------------|
101 | Copyright (c) 2002-2003 Geir Landrö |
102 |--------------------------------------------------*/
105 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
112 vertical-align: middle;
116 text-decoration: none;
118 .dtree a.node, .dtree a.nodeSel {
120 padding: 1px 2px 1px 2px;
122 .dtree a.node:hover, .dtree a.nodeSel:hover {
124 text-decoration: underline;
127 background-color: #c0d2ec;
135 <script language='javascript' src='support/dtree.js'></script>
138 <body style='padding: 25px;'>
140 <a href="$config{index}">Home</a>
142 <h1>User Group Hierarchy Setup</h1>
146 my $uri = $cgi->url(-relative=>1);
149 for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) {
150 my $name = $grp->name;
151 my $desc = $grp->description || $grp->name;
155 <div style="float: left;">
156 <script language='javascript'>
157 var tree = new dTree("tree");
158 tree.add($grp, -1, "$name", "$uri?action=child&id=$grp", "$desc");
164 for my $grp ( permission::grp_tree->search_like( {parent => '%'}, {order_by => 'name'} ) ) {
165 my $name = $grp->name;
166 my $desc = $grp->description || $grp->name;
168 my $parent = $grp->parent;
169 print "\ttree.add($grp, $parent, \"$name\", \"$uri?action=child&id=$grp\", \"$desc\");\n";
173 tree.closeAllChildren($top);
174 document.write(tree.toString());
177 <div style="float:right; width:75%;">
180 #-------------------------------------------------------------------------------
182 #-------------------------------------------------------------------------------
184 if (my $action = $cgi->param('action')) {
185 if ( $action eq 'child' ) {
186 my $id = $cgi->param('id');
188 my $node = permission::grp_tree->retrieve($id);
189 #-----------------------------------------------------------------------
191 #-----------------------------------------------------------------------
193 print "<h2>Edit Group '".$node->name."'</h2>";
194 print "<form method='POST'>".
195 "<table class='table_class'><tr class='header_class'>\n";
203 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
206 th($org_cols{parent}),
207 td("<select name='parent_$node'>".do{
208 my $out = '<option>-- Select One --</option>';
209 for my $org ( sort {$a->id <=> $b->id} permission::grp_tree->retrieve_all) {
210 $out .= "<option value='$org' ".do {
211 if ($node->parent == $org->id) {
213 }}.'>'.$org->name.'</option>'
216 }."</select><input type='hidden' value='$node' name='id'>"),
219 th($org_cols{description}),
220 td("<input type='text' name='description_$node' value=\"". $node->description() ."\">"),
223 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
225 print "</table></form><hr/>";
228 print "<h2>Group Permissions</h2>";
230 print "<form method='POST'>".
231 "<table class='table_class'>\n".
232 "<tr class='header_class'><th>Permission</th><th>Select</th><th>At Depth</th><th>Grantable</th></tr>";
234 for my $perm ( sort {$a->code cmp $b->code} permission::perm_list->retrieve_all ) {
236 my $out = '<select name="depth_'.$perm->id.'"><option value="">-- Select One --</option>';
237 for my $outype ( actor::org_unit_type->retrieve_all ) {
239 $out .= "<option value='".$outype->depth."' ".do{
243 my $setting = permission::grp_perm_map->search(
247 $stuff = "selected " if($setting && $outype->depth == $setting->depth);
248 if($stuff && $setting && $setting->grp != $node->id) {
249 $out =~ s/^<select/<select disabled/o;
252 } while (!$stuff && $grp && ($grp = $grp->parent));
254 }.">".$outype->name."</option>";
257 $out .= "</td><td><input type='checkbox' name='grant_$perm' value='t' ".
262 my $setting = permission::grp_perm_map->search(
266 $stuff = "checked='checked' " if ($setting && $setting->grantable);
268 } while (!$stuff && $grp && ($grp = $grp->parent));
273 print Tr( "<td>".$perm->code."</td><td>".
274 "<input type='checkbox' name='permission_$perm' value='$perm' ".
279 my $setting = permission::grp_perm_map->search(
283 $stuff = "checked " if ($setting);
284 $stuff .= "disabled " if($setting && $setting->grp != $node->id);
286 } while (!$stuff && $grp && ($grp = $grp->parent));
289 "></td><td>$out</td>"
294 print Tr( "<td colspan='3'><input type='hidden' value='$node' name='perms'>",
295 "<input type='submit' name='action' value='Set Permissions'/></td>" );
296 print "</table></form><hr/>";
300 print "<h2>New Child</h2>";
302 print "<form method='POST'>".
303 "<table class='table_class'>\n";
307 td("<input type='text' name='name'>"),
310 th($org_cols{description}),
311 td("<input type='text' name='description'>"),
313 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent'>",
314 "<input type='submit' name='action' value='Add New'/></td>" );
315 print "</table></form><hr/>";
321 print "</div></body></html>";