#!/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_*/; OpenILS::Application::Storage::CDBI->connection('dbi:Pg:host=10.0.0.2;dbname=open-ils-dev', 'postgres'); OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1; my $cgi = new CGI; #------------------------------------------------------------------------------- # setup part #------------------------------------------------------------------------------- my %org_cols = ( qw/id SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName/ ); my @col_display_order = ( qw/id name shortname ou_type parent_ou/ ); if (my $action = $cgi->param('action')) { if ( $action eq 'Update' ) { for my $id ( ($cgi->param('id')) ) { my $u = actor::org_unit->retrieve($id); for my $col ( keys %org_cols ) { $u->$col( $cgi->param($col."_$id") ); } $u->update; } } elsif ( $action eq 'Add New' ) { actor::org_unit->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } ); } } #------------------------------------------------------------------------------- # HTML part #------------------------------------------------------------------------------- print <

Library Hierarchy Setup


HEADER my $uri = $cgi->url(-relative=>1); my $top; for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) { my $name = $lib->name; $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 = actor::org_unit->retrieve($id); #----------------------------------------------------------------------- # child form #----------------------------------------------------------------------- print "

Edit ".$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{shortname}), td(""), ); print Tr( th($org_cols{ou_type}), td(""), ); print Tr( th($org_cols{parent_ou}), td(""), ); print Tr( "" ); print "

"; print "

New Child

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

"; } } } print "
";