#!/usr/bin/perl use strict; # vim:noet:ts=4 use DateTime; 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'; #do '/openils/conf/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 SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName email Email phone Phone opac_visible OPACVisible/ ); my @col_display_order = ( qw/id name shortname ou_type email phone opac_visible 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 ) { next if ($cgi->param($col."_$id") =~ /Select One/o); if ($col eq 'shortname') { $u->$col( uc( $cgi->param($col."_$id") ) ); } else { $u->$col( $cgi->param($col."_$id") ); } } $u->update; } } elsif ( $action eq 'Update Hours' ) { for my $id ( ($cgi->param('id')) ) { my $hoo = actor::org_unit::hours_of_operation->retrieve($id); for my $col ( $hoo->columns('Essential') ) { $hoo->$col( $cgi->param($col) ); } $hoo->update; } } elsif ( $action eq 'Add New' ) { actor::org_unit->create( { map { defined($cgi->param($_)) ? ( $_ eq 'shortname' ? ($_ => uc($cgi->param($_))) : ($_ => $cgi->param($_)) ) : () } keys %org_cols } ); } elsif ( $action eq 'Save Address' ) { my $org = actor::org_unit->retrieve($cgi->param('id')); my $addr = {}; $$addr{org_unit} = $cgi->param('org_unit') || $org->id; $$addr{street1} = $cgi->param('street1'); $$addr{street2} = $cgi->param('street2'); $$addr{city} = $cgi->param('city'); $$addr{county} = $cgi->param('county'); $$addr{state} = $cgi->param('state'); $$addr{country} = $cgi->param('country'); $$addr{post_code} = $cgi->param('post_code'); my $a_type = $cgi->param('addr_type'); my $a = actor::org_address->retrieve($cgi->param('aid')); if ($a) { for (keys %$addr) { next unless $$addr{$_}; $a->$_($$addr{$_}); } $a->update; } else { $a = actor::org_address->create( {map {defined($$addr{$_}) ? ($_ => $$addr{$_}) : ()} keys %$addr} ); } $org->$a_type($a->id); $org->update; } } #------------------------------------------------------------------------------- # HTML part #------------------------------------------------------------------------------- print < Home

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; $top = $lib->id; 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{email}), td("email() ."\">"), ); print Tr( th($org_cols{phone}), td(""), ); print Tr( th($org_cols{opac_visible} .'*'), td("" ), ); print Tr( th($org_cols{parent_ou}), td(""), ); print Tr( "" ); print "
*". "You must hide every OU you want hidden, not just an ancestor!
"; #------------------------------------------------------------------------- # Hours of operation form #------------------------------------------------------------------------- my %dow = ( 0 => 'Monday', 1 => 'Tuesday', 2 => 'Wednesday', 3 => 'Thursday', 4 => 'Friday', 5 => 'Saturday', 6 => 'Sunday', ); print "

Hours of Operation for ".$node->name."

". "
". "\n"; print Tr( th('Day of Week'), th('Open Time'), th('Close Time'), ); my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } ); for my $day ( 0 .. 6 ) { my $open = "dow_${day}_open"; my $close = "dow_${day}_close"; print Tr( th($dow{$day}), td("$open ."\">"), td("$close ."\">"), ); } print Tr( "" ); print "
". "". "
"; #------------------------------------------------------------------------- # Address edit form #------------------------------------------------------------------------- print "

Addresses for ".$node->name."

"; print ""; my %addrs = ( ill_address => 'ILL Address', holds_address => 'Consortial Holds Address', mailing_address => 'Mailing Address', billing_address => 'Physical Address' ); for my $a (qw/billing_address mailing_address holds_address ill_address/) { my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a); my %ah = ( street1 => $addr?$addr->street1:'', street2 => $addr?$addr->street2:'', city => $addr?$addr->city:'', county => $addr?$addr->county:'', state => $addr?$addr->state:'', country => $addr?$addr->country:'US', post_code => $addr?$addr->post_code:'', org_unit => $addr?$addr->org_unit:$node->id, id => $addr?$addr->id:'', ); #print '' if ($a eq 'holds_address'); print <<" TABLE"; TABLE } print "
$addrs{$a}
SysID
*Street 1
Street 2
*City
County
*State
*Country
*ZIP

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( th($org_cols{email}), td(""), ); print Tr( th($org_cols{phone}), td(""), ); print Tr( "" ); print "
", "

"; } } } print "
";