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( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
54 } elsif ( $action eq 'Save Address' ) {
55 my $org = actor::org_unit->retrieve($cgi->param('id'));
59 $$addr{org_unit} = $cgi->param('org_unit') || $org->id;
60 $$addr{street1} = $cgi->param('street1');
61 $$addr{street2} = $cgi->param('street2');
62 $$addr{city} = $cgi->param('city');
63 $$addr{county} = $cgi->param('county');
64 $$addr{state} = $cgi->param('state');
65 $$addr{country} = $cgi->param('country');
66 $$addr{post_code} = $cgi->param('post_code');
68 my $a_type = $cgi->param('addr_type');
71 my $a = actor::org_address->retrieve($cgi->param('aid'));
75 next unless $$addr{$_};
80 $a = actor::org_address->create( {map {defined($$addr{$_}) ? ($_ => $$addr{$_}) : ()} keys %$addr} );
83 $org->$a_type($a->id);
88 #-------------------------------------------------------------------------------
90 #-------------------------------------------------------------------------------
93 Content-type: text/html
100 border: dashed lightgrey 1px;
101 background-color: #EEE;
102 border-collapse: collapse;
114 border: solid lightgrey 1px;
118 background-color: lightblue;
119 border: solid blue 1px;
124 /*--------------------------------------------------|
125 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
126 |---------------------------------------------------|
127 | Copyright (c) 2002-2003 Geir Landrö |
128 |--------------------------------------------------*/
131 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
138 vertical-align: middle;
142 text-decoration: none;
144 .dtree a.node, .dtree a.nodeSel {
146 padding: 1px 2px 1px 2px;
148 .dtree a.node:hover, .dtree a.nodeSel:hover {
150 text-decoration: underline;
153 background-color: #c0d2ec;
161 <script language='javascript' src='support/dtree.js'></script>
164 <body style='padding: 25px;'>
166 <a href="$config{index}">Home</a>
168 <h1>Library Hierarchy Setup</h1>
172 my $uri = $cgi->url(-relative=>1);
175 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
176 my $name = $lib->name;
181 <script language='javascript'>
182 var tree = new dTree("tree");
183 tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
189 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'name'} ) ) {
190 my $name = $lib->name;
192 my $parent = $lib->parent_ou;
193 print "\ttree.add($lib, $parent, \"$name\", \"$uri?action=child&id=$lib\", \"$name\");\n";
197 tree.closeAllChildren($top);
198 document.write(tree.toString());
205 #-------------------------------------------------------------------------------
207 #-------------------------------------------------------------------------------
209 if (my $action = $cgi->param('action')) {
210 if ( $action eq 'child' ) {
211 my $id = $cgi->param('id');
213 my $node = actor::org_unit->retrieve($id);
214 #-----------------------------------------------------------------------
216 #-----------------------------------------------------------------------
218 print "<hr/><h2>Edit ".$node->name."</h2>";
219 print "<form method='POST'>".
220 "<table class='table_class'><tr class='header_class'>\n";
228 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
231 th($org_cols{shortname}),
232 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
235 th($org_cols{ou_type}),
236 td("<select name='ou_type_$node'>".do{
237 my $out = '<option>-- Select One --</option>';
238 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
239 $out .= "<option value='$type' ".do {
240 if ($node->ou_type == $type->id) {
242 }}.'>'.$type->name.'</option>'
248 th($org_cols{email}),
249 td("<input type='text' name='email_$node' value=\"". $node->email() ."\">"),
253 th($org_cols{phone}),
254 td("<input type='text' name='phone_$node' value='". $node->phone() ."'>"),
258 th($org_cols{opac_visible} .'<span style="color:red">*</span>'),
259 td("<select name='opac_visible_$node'>".
261 my $out = "<option value='t' ";
262 $out .= ($node->opac_visible =~ /^[y1t]+/i) ? "selected='yes'" : "";
263 $out .= ">True</option><option value='f' ";
264 $out .= ($node->opac_visible =~ /^[n0f]+/i) ? "selected='yes'" : "";
265 $out .= ">False</option>";
272 th($org_cols{parent_ou}),
273 td("<select name='parent_ou_$node'>".do{
274 my $out = '<option>-- Select One --</option>';
275 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
276 $out .= "<option value='$org' ".do {
277 if ($node->parent_ou == $org->id) {
279 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
282 }."</select><input type='hidden' value='$node' name='id'>"),
285 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
286 print "</table><span style='color:red;'>*</span>".
287 "You must hide every OU you want hidden, not just an anscestor!</form>";
289 #-------------------------------------------------------------------------
290 # Hours of operation form
291 #-------------------------------------------------------------------------
305 print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
306 "<form method='POST'>".
307 "<table class='table_class'><tr class='header_class'>\n";
315 my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
316 for my $day ( 0 .. 6 ) {
317 my $open = "dow_${day}_open";
318 my $close = "dow_${day}_close";
322 td("<input type='text' name='$open' value=\"". $hoo->$open ."\">"),
323 td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
327 print Tr( "<td colspan='3'>".
328 "<input type='hidden' value='$node' name='id'>".
329 "<input type='submit' name='action' value='Update Hours'/></td>"
331 print "</table></form>";
334 #-------------------------------------------------------------------------
336 #-------------------------------------------------------------------------
338 print "<hr/><h2>Adresses for ".$node->name."</h2>";
339 print "<table cellspacing='20'><tr>";
340 my %addrs = ( ill_address => 'ILL Address',
341 holds_address => 'Consortial Holds Address',
342 mailing_address => 'Mailing Address',
343 billing_address => 'Physical Address'
345 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
346 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
348 my %ah = ( street1 => $addr?$addr->street1:'',
349 street2 => $addr?$addr->street2:'',
350 city => $addr?$addr->city:'',
351 county => $addr?$addr->county:'',
352 state => $addr?$addr->state:'',
353 country => $addr?$addr->country:'US',
354 post_code => $addr?$addr->post_code:'',
355 org_unit => $addr?$addr->org_unit:$node->id,
356 id => $addr?$addr->id:'',
359 #print '</tr><tr>' if ($a eq 'holds_address');
364 <table class='table_class'>
366 <th colspan=2>$addrs{$a}</th>
370 <td><input type='text' name='aid' value='$ah{id}'></td>
374 <td><input type='text' name='street1' value='$ah{street1}'></td>
378 <td><input type='text' name='street2' value='$ah{street2}'></td>
382 <td><input type='text' name='city' value='$ah{city}'></td>
386 <td><input type='text' name='county' value='$ah{county}'></td>
390 <td><input type='text' name='state' value='$ah{state}'></td>
394 <td><input type='text' name='country' value='$ah{country}'></td>
398 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
401 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
402 <input type='hidden' name='addr_type' value='$a'>
403 <input type='hidden' name='id' value='$node'>
404 <input type='submit' name='action' value='Save Address'>
410 print "<tr></table><hr><h2>New Child</h2>";
412 print "<form method='POST'>".
413 "<table class='table_class'>\n";
417 td("<input type='text' name='name'>"),
420 th($org_cols{shortname}),
421 td("<input type='text' name='shortname'>"),
424 th($org_cols{ou_type}),
425 td("<select name='ou_type'>".do{
426 my $out = '<option>-- Select One --</option>';
427 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
428 $out .= "<option value='$type'>".$type->name.'</option>'
434 th($org_cols{email}),
435 td("<input type='text' name='email'>"),
438 th($org_cols{phone}),
439 td("<input type='text' name='phone'>"),
442 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
443 "<input type='submit' name='action' value='Add New'/></td>" );
444 print "</table></form><hr/>";
449 print "</div></body></html>";