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/ );
28 my @col_display_order = ( qw/id name shortname ou_type 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 $u->$col( $cgi->param($col."_$id") );
40 } elsif ( $action eq 'Update Hours' ) {
41 for my $id ( ($cgi->param('id')) ) {
42 my $hoo = actor::org_unit::hours_of_operation->retrieve($id);
43 for my $col ( $hoo->columns('Essential') ) {
44 $hoo->$col( $cgi->param($col) );
48 } elsif ( $action eq 'Add New' ) {
49 actor::org_unit->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
50 } elsif ( $action eq 'Save Address' ) {
51 my $org = actor::org_unit->retrieve($cgi->param('id'));
55 $$addr{org_unit} = $cgi->param('org_unit') || $org->id;
56 $$addr{street1} = $cgi->param('street1');
57 $$addr{street2} = $cgi->param('street2');
58 $$addr{city} = $cgi->param('city');
59 $$addr{county} = $cgi->param('county');
60 $$addr{state} = $cgi->param('state');
61 $$addr{country} = $cgi->param('country');
62 $$addr{post_code} = $cgi->param('post_code');
64 my $a_type = $cgi->param('addr_type');
67 my $a = actor::org_address->retrieve($cgi->param('aid'));
71 next unless $$addr{$_};
76 $a = actor::org_address->create( {map {defined($$addr{$_}) ? ($_ => $$addr{$_}) : ()} keys %$addr} );
79 $org->$a_type($a->id);
84 #-------------------------------------------------------------------------------
86 #-------------------------------------------------------------------------------
89 Content-type: text/html
96 border: dashed lightgrey 1px;
97 background-color: #EEE;
98 border-collapse: collapse;
110 border: solid lightgrey 1px;
114 background-color: lightblue;
115 border: solid blue 1px;
120 /*--------------------------------------------------|
121 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
122 |---------------------------------------------------|
123 | Copyright (c) 2002-2003 Geir Landrö |
124 |--------------------------------------------------*/
127 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
134 vertical-align: middle;
138 text-decoration: none;
140 .dtree a.node, .dtree a.nodeSel {
142 padding: 1px 2px 1px 2px;
144 .dtree a.node:hover, .dtree a.nodeSel:hover {
146 text-decoration: underline;
149 background-color: #c0d2ec;
157 <script language='javascript' src='support/dtree.js'></script>
160 <body style='padding: 25px;'>
162 <a href="$config{index}">Home</a>
164 <h1>Library Hierarchy Setup</h1>
168 my $uri = $cgi->url(-relative=>1);
171 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
172 my $name = $lib->name;
177 <script language='javascript'>
178 var tree = new dTree("tree");
179 tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
185 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'name'} ) ) {
186 my $name = $lib->name;
188 my $parent = $lib->parent_ou;
189 print "\ttree.add($lib, $parent, \"$name\", \"$uri?action=child&id=$lib\", \"$name\");\n";
193 tree.closeAllChildren($top);
194 document.write(tree.toString());
201 #-------------------------------------------------------------------------------
203 #-------------------------------------------------------------------------------
205 if (my $action = $cgi->param('action')) {
206 if ( $action eq 'child' ) {
207 my $id = $cgi->param('id');
209 my $node = actor::org_unit->retrieve($id);
210 #-----------------------------------------------------------------------
212 #-----------------------------------------------------------------------
214 print "<hr/><h2>Edit ".$node->name."</h2>";
215 print "<form method='POST'>".
216 "<table class='table_class'><tr class='header_class'>\n";
224 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
227 th($org_cols{shortname}),
228 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
231 th($org_cols{ou_type}),
232 td("<select name='ou_type_$node'>".do{
233 my $out = '<option>-- Select One --</option>';
234 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
235 $out .= "<option value='$type' ".do {
236 if ($node->ou_type == $type->id) {
238 }}.'>'.$type->name.'</option>'
244 th($org_cols{parent_ou}),
245 td("<select name='parent_ou_$node'>".do{
246 my $out = '<option>-- Select One --</option>';
247 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
248 $out .= "<option value='$org' ".do {
249 if ($node->parent_ou == $org->id) {
251 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
254 }."</select><input type='hidden' value='$node' name='id'>"),
257 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
258 print "</table></form>";
260 #-------------------------------------------------------------------------
261 # Hours of operation form
262 #-------------------------------------------------------------------------
276 print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
277 "<form method='POST'>".
278 "<table class='table_class'><tr class='header_class'>\n";
286 my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
287 for my $day ( 0 .. 6 ) {
288 my $open = "dow_${day}_open";
289 my $close = "dow_${day}_close";
293 td("<input type='text' name='$open' value=\"". $hoo->$open ."\">"),
294 td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
298 print Tr( "<td colspan='3'>".
299 "<input type='hidden' value='$node' name='id'>".
300 "<input type='submit' name='action' value='Update Hours'/></td>"
302 print "</table></form>";
305 #-------------------------------------------------------------------------
307 #-------------------------------------------------------------------------
309 print "<hr/><h2>Adresses for ".$node->name."</h2>";
310 print "<table cellspacing='20'><tr>";
311 my %addrs = ( ill_address => 'ILL Address',
312 holds_address => 'Consortial Holds Address',
313 mailing_address => 'Mailing Address',
314 billing_address => 'Physical Address'
316 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
317 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
319 my %ah = ( street1 => $addr?$addr->street1:'',
320 street2 => $addr?$addr->street2:'',
321 city => $addr?$addr->city:'',
322 county => $addr?$addr->county:'',
323 state => $addr?$addr->state:'',
324 country => $addr?$addr->country:'US',
325 post_code => $addr?$addr->post_code:'',
326 org_unit => $addr?$addr->org_unit:$node->id,
327 id => $addr?$addr->id:'',
330 #print '</tr><tr>' if ($a eq 'holds_address');
335 <table class='table_class'>
337 <th colspan=2>$addrs{$a}</th>
341 <td><input type='text' name='aid' value='$ah{id}'></td>
345 <td><input type='text' name='street1' value='$ah{street1}'></td>
349 <td><input type='text' name='street2' value='$ah{street2}'></td>
353 <td><input type='text' name='city' value='$ah{city}'></td>
357 <td><input type='text' name='county' value='$ah{county}'></td>
361 <td><input type='text' name='state' value='$ah{state}'></td>
365 <td><input type='text' name='country' value='$ah{country}'></td>
369 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
372 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
373 <input type='hidden' name='addr_type' value='$a'>
374 <input type='hidden' name='id' value='$node'>
375 <input type='submit' name='action' value='Save Address'>
381 print "<tr></table><hr><h2>New Child</h2>";
383 print "<form method='POST'>".
384 "<table class='table_class'>\n";
388 td("<input type='text' name='name'>"),
391 th($org_cols{shortname}),
392 td("<input type='text' name='shortname'>"),
395 th($org_cols{ou_type}),
396 td("<select name='ou_type'>".do{
397 my $out = '<option>-- Select One --</option>';
398 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
399 $out .= "<option value='$type'>".$type->name.'</option>'
404 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
405 "<input type='submit' name='action' value='Add New'/></td>" );
406 print "</table></form><hr/>";
411 print "</div></body></html>";