#!/usr/bin/perl use strict; use OpenILS::Application::Storage; use OpenILS::Application::Storage::CDBI; # I need to abstract the driver loading away... use OpenILS::Application::Storage::Driver::Pg; use CGI qw/:standard start_*/; our %config; do '##CONFIG##/live-db-setup.pl'; OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw}); OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1; my $cgi = new CGI; #------------------------------------------------------------------------------- # setup part #------------------------------------------------------------------------------- my %org_cols = ( qw/id GroupID name Name parent ParentGroup description Description/ ); my @col_display_order = ( qw/id name parent description/ ); if (my $action = $cgi->param('action')) { if ( $action eq 'Update' ) { for my $id ( ($cgi->param('id')) ) { my $u = permission::grp_tree->retrieve($id); for my $col ( keys %org_cols ) { next if ($cgi->param($col."_$id") =~ /Select One/o); $u->$col( $cgi->param($col."_$id") ); } $u->update; } } elsif ( $action eq 'Set Permissions' ) { my $grp = permission::grp_tree->retrieve($cgi->param('perms')); my @ids = $cgi->param('permission'); for my $perm ( permission::perm_list->retrieve_all ) { if (my $id = $cgi->param('permission_'.$perm->id) ) { my $p = permission::grp_perm_map->search({perm=>$id,grp=>$grp->id})->next; my $d = $cgi->param("depth_$id"); if (!$p) { $p = permission::grp_perm_map->create({perm=>$id,grp=>$grp->id,depth=>$d}); } else { $p->depth( $d ); } $p->update; } else { permission::grp_perm_map->search({perm=>$perm->id,grp=>$grp->id})->delete_all; } } $cgi->param('action'=>'child'); } elsif ( $action eq 'Add New' ) { permission::grp_tree->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } ); } } #------------------------------------------------------------------------------- # HTML part #------------------------------------------------------------------------------- print < Home

User Group Hierarchy Setup


HEADER my $uri = $cgi->url(-relative=>1); my $top; for my $grp ( permission::grp_tree->search( {parent=>undef} ) ) { my $name = $grp->name; my $desc = $grp->description || $grp->name; $top = $grp->id; $name =~ s/'/\\'/og; print <<" HEADER";
HEADER #------------------------------------------------------------------------------- # Logic part #------------------------------------------------------------------------------- if (my $action = $cgi->param('action')) { if ( $action eq 'child' ) { my $id = $cgi->param('id'); if ($id) { my $node = permission::grp_tree->retrieve($id); #----------------------------------------------------------------------- # child form #----------------------------------------------------------------------- print "

Edit Group '".$node->name."'

"; print "
". "\n"; print Tr( th($org_cols{id}), td( $node->id() ), ); print Tr( th($org_cols{name}), td("name() ."\">"), ); print Tr( th($org_cols{parent}), td(""), ); print Tr( th($org_cols{description}), td("description() ."\">"), ); print Tr( "" ); print "

"; print "

Group Permissions

"; print "
". "\n". ""; for my $perm ( sort {$a->code cmp $b->code} permission::perm_list->retrieve_all ) { my $grp = $node; my $out = 'parent)); $stuff; }.">".$outype->name.""; } $out .= ""; $grp = $node; print Tr( "" ); } print Tr( "" ); print "
PermissionSelectAt Depth
".$perm->code."". "search( { grp => $grp->id, perm => $perm->id } )->next; $stuff = "checked " if ($setting); $stuff .= "disabled " if($setting && $setting->grp != $node->id); } } while (!$stuff && $grp && ($grp = $grp->parent)); $stuff; }. ">$out", "

"; print "

New Child

"; print "
". "\n"; print Tr( th($org_cols{name}), td(""), ); print Tr( th($org_cols{description}), td(""), ); print Tr( "" ); print "
", "

"; } } } print "
";