5 use OpenILS::Application::Storage;
6 use OpenILS::Application::Storage::CDBI;
8 # I need to abstract the driver loading away...
9 use OpenILS::Application::Storage::Driver::Pg;
11 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;
21 #-------------------------------------------------------------------------------
23 #-------------------------------------------------------------------------------
25 my %org_cols = ( qw/id SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName/ );
27 my @col_display_order = ( qw/id name shortname ou_type parent_ou/ );
29 if (my $action = $cgi->param('action')) {
30 if ( $action eq 'Update' ) {
31 for my $id ( ($cgi->param('id')) ) {
32 my $u = actor::org_unit->retrieve($id);
33 for my $col ( keys %org_cols ) {
34 next if ($cgi->param($col."_$id") =~ /Select One/o);
35 $u->$col( $cgi->param($col."_$id") );
39 } elsif ( $action eq 'Update Hours' ) {
40 for my $id ( ($cgi->param('id')) ) {
41 my $hoo = actor::org_unit::hours_of_operation->retrieve($id);
42 for my $col ( $hoo->columns('Essential') ) {
43 $hoo->$col( $cgi->param($col) );
47 } elsif ( $action eq 'Add New' ) {
48 actor::org_unit->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
49 } elsif ( $action eq 'Save Address' ) {
50 my $org = actor::org_unit->retrieve($cgi->param('id'));
54 $$addr{org_unit} = $cgi->param('org_unit') || $org->id;
55 $$addr{street1} = $cgi->param('street1');
56 $$addr{street2} = $cgi->param('street2');
57 $$addr{city} = $cgi->param('city');
58 $$addr{county} = $cgi->param('county');
59 $$addr{state} = $cgi->param('state');
60 $$addr{country} = $cgi->param('country');
61 $$addr{post_code} = $cgi->param('post_code');
63 my $a_type = $cgi->param('addr_type');
66 my $a = actor::org_address->retrieve($cgi->param('aid'));
70 next unless $$addr{$_};
75 $a = actor::org_address->create( {map {defined($$addr{$_}) ? ($_ => $$addr{$_}) : ()} keys %$addr} );
78 $org->$a_type($a->id);
83 #-------------------------------------------------------------------------------
85 #-------------------------------------------------------------------------------
88 Content-type: text/html
95 border: dashed lightgrey 1px;
96 background-color: #EEE;
97 border-collapse: collapse;
109 border: solid lightgrey 1px;
113 background-color: lightblue;
114 border: solid blue 1px;
119 /*--------------------------------------------------|
120 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
121 |---------------------------------------------------|
122 | Copyright (c) 2002-2003 Geir Landrö |
123 |--------------------------------------------------*/
126 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
133 vertical-align: middle;
137 text-decoration: none;
139 .dtree a.node, .dtree a.nodeSel {
141 padding: 1px 2px 1px 2px;
143 .dtree a.node:hover, .dtree a.nodeSel:hover {
145 text-decoration: underline;
148 background-color: #c0d2ec;
156 <script language='javascript' src='support/dtree.js'></script>
159 <body style='padding: 25px;'>
161 <a href="$config{index}">Home</a>
163 <h1>Library Hierarchy Setup</h1>
167 my $uri = $cgi->url(-relative=>1);
170 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
171 my $name = $lib->name;
176 <script language='javascript'>
177 var tree = new dTree("tree");
178 tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
184 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'name'} ) ) {
185 my $name = $lib->name;
187 my $parent = $lib->parent_ou;
188 print "\ttree.add($lib, $parent, \"$name\", \"$uri?action=child&id=$lib\", \"$name\");\n";
192 tree.closeAllChildren($top);
193 document.write(tree.toString());
200 #-------------------------------------------------------------------------------
202 #-------------------------------------------------------------------------------
204 if (my $action = $cgi->param('action')) {
205 if ( $action eq 'child' ) {
206 my $id = $cgi->param('id');
208 my $node = actor::org_unit->retrieve($id);
209 #-----------------------------------------------------------------------
211 #-----------------------------------------------------------------------
213 print "<hr/><h2>Edit ".$node->name."</h2>";
214 print "<form method='POST'>".
215 "<table class='table_class'><tr class='header_class'>\n";
223 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
226 th($org_cols{shortname}),
227 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
230 th($org_cols{ou_type}),
231 td("<select name='ou_type_$node'>".do{
232 my $out = '<option>-- Select One --</option>';
233 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
234 $out .= "<option value='$type' ".do {
235 if ($node->ou_type == $type->id) {
237 }}.'>'.$type->name.'</option>'
243 th($org_cols{parent_ou}),
244 td("<select name='parent_ou_$node'>".do{
245 my $out = '<option>-- Select One --</option>';
246 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
247 $out .= "<option value='$org' ".do {
248 if ($node->parent_ou == $org->id) {
250 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
253 }."</select><input type='hidden' value='$node' name='id'>"),
256 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
257 print "</table></form>";
259 #-------------------------------------------------------------------------
260 # Hours of operation form
261 #-------------------------------------------------------------------------
275 print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
276 "<form method='POST'>".
277 "<table class='table_class'><tr class='header_class'>\n";
285 my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
286 for my $day ( 0 .. 6 ) {
287 my $open = "dow_${day}_open";
288 my $close = "dow_${day}_close";
292 td("<input type='text' name='$open' value=\"". $hoo->$open ."\">"),
293 td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
297 print Tr( "<td colspan='3'>".
298 "<input type='hidden' value='$node' name='id'>".
299 "<input type='submit' name='action' value='Update Hours'/></td>"
301 print "</table></form>";
304 #-------------------------------------------------------------------------
306 #-------------------------------------------------------------------------
308 print "<hr/><h2>Adresses for ".$node->name."</h2>";
309 print "<table cellspacing='20'><tr>";
310 my %addrs = ( ill_address => 'ILL Address',
311 holds_address => 'Consortial Holds Address',
312 mailing_address => 'Mailing Address',
313 billing_address => 'Physical Address'
315 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
316 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
318 my %ah = ( street1 => $addr?$addr->street1:'',
319 street2 => $addr?$addr->street2:'',
320 city => $addr?$addr->city:'',
321 county => $addr?$addr->county:'',
322 state => $addr?$addr->state:'',
323 country => $addr?$addr->country:'US',
324 post_code => $addr?$addr->post_code:'',
325 org_unit => $addr?$addr->org_unit:$node->id,
326 id => $addr?$addr->id:'',
329 #print '</tr><tr>' if ($a eq 'holds_address');
334 <table class='table_class'>
336 <th colspan=2>$addrs{$a}</th>
340 <td><input type='text' name='aid' value='$ah{id}'></td>
344 <td><input type='text' name='street1' value='$ah{street1}'></td>
348 <td><input type='text' name='street2' value='$ah{street2}'></td>
352 <td><input type='text' name='city' value='$ah{city}'></td>
356 <td><input type='text' name='county' value='$ah{county}'></td>
360 <td><input type='text' name='state' value='$ah{state}'></td>
364 <td><input type='text' name='country' value='$ah{country}'></td>
368 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
371 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
372 <input type='hidden' name='addr_type' value='$a'>
373 <input type='hidden' name='id' value='$node'>
374 <input type='submit' name='action' value='Save Address'>
380 print "<tr></table><hr><h2>New Child</h2>";
382 print "<form method='POST'>".
383 "<table class='table_class'>\n";
387 td("<input type='text' name='name'>"),
390 th($org_cols{shortname}),
391 td("<input type='text' name='shortname'>"),
394 th($org_cols{ou_type}),
395 td("<select name='ou_type'>".do{
396 my $out = '<option>-- Select One --</option>';
397 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
398 $out .= "<option value='$type'>".$type->name.'</option>'
403 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
404 "<input type='submit' name='action' value='Add New'/></td>" );
405 print "</table></form><hr/>";
410 print "</div></body></html>";