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
108 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
111 border: dashed lightgrey 1px;
112 background-color: #EEE;
113 border-collapse: collapse;
125 border: solid lightgrey 1px;
129 background-color: lightblue;
130 border: solid blue 1px;
135 /*--------------------------------------------------|
136 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
137 |---------------------------------------------------|
138 | Copyright (c) 2002-2003 Geir Landrö |
139 |--------------------------------------------------*/
142 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
149 vertical-align: middle;
153 text-decoration: none;
155 .dtree a.node, .dtree a.nodeSel {
157 padding: 1px 2px 1px 2px;
159 .dtree a.node:hover, .dtree a.nodeSel:hover {
161 text-decoration: underline;
164 background-color: #c0d2ec;
172 <script language='javascript' src='support/dtree.js'></script>
175 <body style='padding: 25px;'>
177 <a href="$config{index}">Home</a>
179 <h1>Library Hierarchy Setup</h1>
183 my $uri = $cgi->url(-relative=>1);
186 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
187 my $name = $lib->name;
192 <script language='javascript'>
193 var tree = new dTree("tree");
194 tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
200 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'name'} ) ) {
201 my $name = $lib->name;
203 my $parent = $lib->parent_ou;
204 print "\ttree.add($lib, $parent, \"$name\", \"$uri?action=child&id=$lib\", \"$name\");\n";
208 tree.closeAllChildren($top);
209 document.write(tree.toString());
216 #-------------------------------------------------------------------------------
218 #-------------------------------------------------------------------------------
220 if (my $action = $cgi->param('action')) {
221 if ( $action eq 'child' ) {
222 my $id = $cgi->param('id');
224 my $node = actor::org_unit->retrieve($id);
225 #-----------------------------------------------------------------------
227 #-----------------------------------------------------------------------
229 print "<hr/><h2>Edit ".$node->name."</h2>";
230 print "<form method='POST'>".
231 "<table class='table_class'><tr class='header_class'>\n";
239 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
242 th($org_cols{shortname}),
243 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
246 th($org_cols{ou_type}),
247 td("<select name='ou_type_$node'>".do{
248 my $out = '<option>-- Select One --</option>';
249 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
250 $out .= "<option value='$type' ".do {
251 if ($node->ou_type == $type->id) {
253 }}.'>'.$type->name.'</option>'
259 th($org_cols{email}),
260 td("<input type='text' name='email_$node' value=\"". $node->email() ."\">"),
264 th($org_cols{phone}),
265 td("<input type='text' name='phone_$node' value='". $node->phone() ."'>"),
269 th($org_cols{opac_visible} .'<span style="color:red">*</span>'),
270 td("<select name='opac_visible_$node'>".
272 my $out = "<option value='t' ";
273 $out .= ($node->opac_visible =~ /^[y1t]+/i) ? "selected='yes'" : "";
274 $out .= ">True</option><option value='f' ";
275 $out .= ($node->opac_visible =~ /^[n0f]+/i) ? "selected='yes'" : "";
276 $out .= ">False</option>";
283 th($org_cols{parent_ou}),
284 td("<select name='parent_ou_$node'>".do{
285 my $out = '<option>-- Select One --</option>';
286 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
287 $out .= "<option value='$org' ".do {
288 if ($node->parent_ou == $org->id) {
290 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
293 }."</select><input type='hidden' value='$node' name='id'>"),
296 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
297 print "</table><span style='color:red;'>*</span>".
298 "You must hide every OU you want hidden, not just an anscestor!</form>";
300 #-------------------------------------------------------------------------
301 # Hours of operation form
302 #-------------------------------------------------------------------------
316 print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
317 "<form method='POST'>".
318 "<table class='table_class'><tr class='header_class'>\n";
326 my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
327 for my $day ( 0 .. 6 ) {
328 my $open = "dow_${day}_open";
329 my $close = "dow_${day}_close";
333 td("<input type='text' name='$open' value=\"". $hoo->$open ."\">"),
334 td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
338 print Tr( "<td colspan='3'>".
339 "<input type='hidden' value='$node' name='id'>".
340 "<input type='submit' name='action' value='Update Hours'/></td>"
342 print "</table></form>";
345 #-------------------------------------------------------------------------
347 #-------------------------------------------------------------------------
349 print "<hr/><h2>Adresses for ".$node->name."</h2>";
350 print "<table cellspacing='20'><tr>";
351 my %addrs = ( ill_address => 'ILL Address',
352 holds_address => 'Consortial Holds Address',
353 mailing_address => 'Mailing Address',
354 billing_address => 'Physical Address'
356 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
357 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
359 my %ah = ( street1 => $addr?$addr->street1:'',
360 street2 => $addr?$addr->street2:'',
361 city => $addr?$addr->city:'',
362 county => $addr?$addr->county:'',
363 state => $addr?$addr->state:'',
364 country => $addr?$addr->country:'US',
365 post_code => $addr?$addr->post_code:'',
366 org_unit => $addr?$addr->org_unit:$node->id,
367 id => $addr?$addr->id:'',
370 #print '</tr><tr>' if ($a eq 'holds_address');
375 <table class='table_class'>
377 <th colspan=2>$addrs{$a}</th>
381 <td><input type='text' name='aid' value='$ah{id}'></td>
385 <td><input type='text' name='street1' value='$ah{street1}'></td>
389 <td><input type='text' name='street2' value='$ah{street2}'></td>
393 <td><input type='text' name='city' value='$ah{city}'></td>
397 <td><input type='text' name='county' value='$ah{county}'></td>
401 <td><input type='text' name='state' value='$ah{state}'></td>
405 <td><input type='text' name='country' value='$ah{country}'></td>
409 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
412 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
413 <input type='hidden' name='addr_type' value='$a'>
414 <input type='hidden' name='id' value='$node'>
415 <input type='submit' name='action' value='Save Address'>
421 print "<tr></table><hr><h2>New Child</h2>";
423 print "<form method='POST'>".
424 "<table class='table_class'>\n";
428 td("<input type='text' name='name'>"),
431 th($org_cols{shortname}),
432 td("<input type='text' name='shortname'>"),
435 th($org_cols{ou_type}),
436 td("<select name='ou_type'>".do{
437 my $out = '<option>-- Select One --</option>';
438 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
439 $out .= "<option value='$type'>".$type->name.'</option>'
445 th($org_cols{email}),
446 td("<input type='text' name='email'>"),
449 th($org_cols{phone}),
450 td("<input type='text' name='phone'>"),
453 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
454 "<input type='submit' name='action' value='Add New'/></td>" );
455 print "</table></form><hr/>";
460 print "</div></body></html>";