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';
14 #do '/openils/conf/live-db-setup.pl';
16 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
17 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
22 #-------------------------------------------------------------------------------
24 #-------------------------------------------------------------------------------
26 my %org_cols = ( qw/id SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName email Email phone Phone opac_visible OPACVisible/ );
28 my @col_display_order = ( qw/id name shortname ou_type email phone opac_visible parent_ou/ );
30 if (my $action = $cgi->param('action')) {
31 if ( $action eq 'Update' ) {
32 for my $id ( ($cgi->param('id')) ) {
33 my $u = actor::org_unit->retrieve($id);
34 for my $col ( keys %org_cols ) {
35 next if ($cgi->param($col."_$id") =~ /Select One/o);
36 if ($col eq 'shortname') {
37 $u->$col( uc( $cgi->param($col."_$id") ) );
39 $u->$col( $cgi->param($col."_$id") );
44 } elsif ( $action eq 'Update Hours' ) {
45 for my $id ( ($cgi->param('id')) ) {
46 my $hoo = actor::org_unit::hours_of_operation->retrieve($id);
47 for my $col ( $hoo->columns('Essential') ) {
48 $hoo->$col( $cgi->param($col) );
52 } elsif ( $action eq 'Add New' ) {
53 actor::org_unit->create(
55 defined($cgi->param($_)) ?
57 ($_ => uc($cgi->param($_))) :
58 ($_ => $cgi->param($_))
64 } elsif ( $action eq 'Save Address' ) {
65 my $org = actor::org_unit->retrieve($cgi->param('id'));
69 $$addr{org_unit} = $cgi->param('org_unit') || $org->id;
70 $$addr{street1} = $cgi->param('street1');
71 $$addr{street2} = $cgi->param('street2');
72 $$addr{city} = $cgi->param('city');
73 $$addr{county} = $cgi->param('county');
74 $$addr{state} = $cgi->param('state');
75 $$addr{country} = $cgi->param('country');
76 $$addr{post_code} = $cgi->param('post_code');
78 my $a_type = $cgi->param('addr_type');
81 my $a = actor::org_address->retrieve($cgi->param('aid'));
85 next unless $$addr{$_};
90 $a = actor::org_address->create( {map {defined($$addr{$_}) ? ($_ => $$addr{$_}) : ()} keys %$addr} );
93 $org->$a_type($a->id);
98 #-------------------------------------------------------------------------------
100 #-------------------------------------------------------------------------------
103 Content-type: text/html
110 border: dashed lightgrey 1px;
111 background-color: #EEE;
112 border-collapse: collapse;
124 border: solid lightgrey 1px;
128 background-color: lightblue;
129 border: solid blue 1px;
134 /*--------------------------------------------------|
135 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
136 |---------------------------------------------------|
137 | Copyright (c) 2002-2003 Geir Landrö |
138 |--------------------------------------------------*/
141 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
148 vertical-align: middle;
152 text-decoration: none;
154 .dtree a.node, .dtree a.nodeSel {
156 padding: 1px 2px 1px 2px;
158 .dtree a.node:hover, .dtree a.nodeSel:hover {
160 text-decoration: underline;
163 background-color: #c0d2ec;
171 <script language='javascript' src='support/dtree.js'></script>
174 <body style='padding: 25px;'>
176 <a href="$config{index}">Home</a>
178 <h1>Library Hierarchy Setup</h1>
182 my $uri = $cgi->url(-relative=>1);
185 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
186 my $name = $lib->name;
191 <script language='javascript'>
192 var tree = new dTree("tree");
193 tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
199 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'name'} ) ) {
200 my $name = $lib->name;
202 my $parent = $lib->parent_ou;
203 print "\ttree.add($lib, $parent, \"$name\", \"$uri?action=child&id=$lib\", \"$name\");\n";
207 tree.closeAllChildren($top);
208 document.write(tree.toString());
215 #-------------------------------------------------------------------------------
217 #-------------------------------------------------------------------------------
219 if (my $action = $cgi->param('action')) {
220 if ( $action eq 'child' ) {
221 my $id = $cgi->param('id');
223 my $node = actor::org_unit->retrieve($id);
224 #-----------------------------------------------------------------------
226 #-----------------------------------------------------------------------
228 print "<hr/><h2>Edit ".$node->name."</h2>";
229 print "<form method='POST'>".
230 "<table class='table_class'><tr class='header_class'>\n";
238 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
241 th($org_cols{shortname}),
242 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
245 th($org_cols{ou_type}),
246 td("<select name='ou_type_$node'>".do{
247 my $out = '<option>-- Select One --</option>';
248 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
249 $out .= "<option value='$type' ".do {
250 if ($node->ou_type == $type->id) {
252 }}.'>'.$type->name.'</option>'
258 th($org_cols{email}),
259 td("<input type='text' name='email_$node' value=\"". $node->email() ."\">"),
263 th($org_cols{phone}),
264 td("<input type='text' name='phone_$node' value='". $node->phone() ."'>"),
268 th($org_cols{opac_visible} .'<span style="color:red">*</span>'),
269 td("<select name='opac_visible_$node'>".
271 my $out = "<option value='t' ";
272 $out .= ($node->opac_visible =~ /^[y1t]+/i) ? "selected='yes'" : "";
273 $out .= ">True</option><option value='f' ";
274 $out .= ($node->opac_visible =~ /^[n0f]+/i) ? "selected='yes'" : "";
275 $out .= ">False</option>";
282 th($org_cols{parent_ou}),
283 td("<select name='parent_ou_$node'>".do{
284 my $out = '<option>-- Select One --</option>';
285 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
286 $out .= "<option value='$org' ".do {
287 if ($node->parent_ou == $org->id) {
289 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
292 }."</select><input type='hidden' value='$node' name='id'>"),
295 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
296 print "</table><span style='color:red;'>*</span>".
297 "You must hide every OU you want hidden, not just an anscestor!</form>";
299 #-------------------------------------------------------------------------
300 # Hours of operation form
301 #-------------------------------------------------------------------------
315 print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
316 "<form method='POST'>".
317 "<table class='table_class'><tr class='header_class'>\n";
325 my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
326 for my $day ( 0 .. 6 ) {
327 my $open = "dow_${day}_open";
328 my $close = "dow_${day}_close";
332 td("<input type='text' name='$open' value=\"". $hoo->$open ."\">"),
333 td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
337 print Tr( "<td colspan='3'>".
338 "<input type='hidden' value='$node' name='id'>".
339 "<input type='submit' name='action' value='Update Hours'/></td>"
341 print "</table></form>";
344 #-------------------------------------------------------------------------
346 #-------------------------------------------------------------------------
348 print "<hr/><h2>Adresses for ".$node->name."</h2>";
349 print "<table cellspacing='20'><tr>";
350 my %addrs = ( ill_address => 'ILL Address',
351 holds_address => 'Consortial Holds Address',
352 mailing_address => 'Mailing Address',
353 billing_address => 'Physical Address'
355 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
356 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
358 my %ah = ( street1 => $addr?$addr->street1:'',
359 street2 => $addr?$addr->street2:'',
360 city => $addr?$addr->city:'',
361 county => $addr?$addr->county:'',
362 state => $addr?$addr->state:'',
363 country => $addr?$addr->country:'US',
364 post_code => $addr?$addr->post_code:'',
365 org_unit => $addr?$addr->org_unit:$node->id,
366 id => $addr?$addr->id:'',
369 #print '</tr><tr>' if ($a eq 'holds_address');
374 <table class='table_class'>
376 <th colspan=2>$addrs{$a}</th>
380 <td><input type='text' name='aid' value='$ah{id}'></td>
384 <td><input type='text' name='street1' value='$ah{street1}'></td>
388 <td><input type='text' name='street2' value='$ah{street2}'></td>
392 <td><input type='text' name='city' value='$ah{city}'></td>
396 <td><input type='text' name='county' value='$ah{county}'></td>
400 <td><input type='text' name='state' value='$ah{state}'></td>
404 <td><input type='text' name='country' value='$ah{country}'></td>
408 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
411 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
412 <input type='hidden' name='addr_type' value='$a'>
413 <input type='hidden' name='id' value='$node'>
414 <input type='submit' name='action' value='Save Address'>
420 print "<tr></table><hr><h2>New Child</h2>";
422 print "<form method='POST'>".
423 "<table class='table_class'>\n";
427 td("<input type='text' name='name'>"),
430 th($org_cols{shortname}),
431 td("<input type='text' name='shortname'>"),
434 th($org_cols{ou_type}),
435 td("<select name='ou_type'>".do{
436 my $out = '<option>-- Select One --</option>';
437 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
438 $out .= "<option value='$type'>".$type->name.'</option>'
444 th($org_cols{email}),
445 td("<input type='text' name='email'>"),
448 th($org_cols{phone}),
449 td("<input type='text' name='phone'>"),
452 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
453 "<input type='submit' name='action' value='Add New'/></td>" );
454 print "</table></form><hr/>";
459 print "</div></body></html>";