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/ );
28 my @col_display_order = ( qw/id name shortname ou_type email phone 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() ."\">"),
252 th($org_cols{phone}),
253 td("<input type='text' name='phone_$node' value='". $node->phone() ."'>"),
257 th($org_cols{parent_ou}),
258 td("<select name='parent_ou_$node'>".do{
259 my $out = '<option>-- Select One --</option>';
260 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
261 $out .= "<option value='$org' ".do {
262 if ($node->parent_ou == $org->id) {
264 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
267 }."</select><input type='hidden' value='$node' name='id'>"),
270 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
271 print "</table></form>";
273 #-------------------------------------------------------------------------
274 # Hours of operation form
275 #-------------------------------------------------------------------------
289 print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
290 "<form method='POST'>".
291 "<table class='table_class'><tr class='header_class'>\n";
299 my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
300 for my $day ( 0 .. 6 ) {
301 my $open = "dow_${day}_open";
302 my $close = "dow_${day}_close";
306 td("<input type='text' name='$open' value=\"". $hoo->$open ."\">"),
307 td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
311 print Tr( "<td colspan='3'>".
312 "<input type='hidden' value='$node' name='id'>".
313 "<input type='submit' name='action' value='Update Hours'/></td>"
315 print "</table></form>";
318 #-------------------------------------------------------------------------
320 #-------------------------------------------------------------------------
322 print "<hr/><h2>Adresses for ".$node->name."</h2>";
323 print "<table cellspacing='20'><tr>";
324 my %addrs = ( ill_address => 'ILL Address',
325 holds_address => 'Consortial Holds Address',
326 mailing_address => 'Mailing Address',
327 billing_address => 'Physical Address'
329 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
330 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
332 my %ah = ( street1 => $addr?$addr->street1:'',
333 street2 => $addr?$addr->street2:'',
334 city => $addr?$addr->city:'',
335 county => $addr?$addr->county:'',
336 state => $addr?$addr->state:'',
337 country => $addr?$addr->country:'US',
338 post_code => $addr?$addr->post_code:'',
339 org_unit => $addr?$addr->org_unit:$node->id,
340 id => $addr?$addr->id:'',
343 #print '</tr><tr>' if ($a eq 'holds_address');
348 <table class='table_class'>
350 <th colspan=2>$addrs{$a}</th>
354 <td><input type='text' name='aid' value='$ah{id}'></td>
358 <td><input type='text' name='street1' value='$ah{street1}'></td>
362 <td><input type='text' name='street2' value='$ah{street2}'></td>
366 <td><input type='text' name='city' value='$ah{city}'></td>
370 <td><input type='text' name='county' value='$ah{county}'></td>
374 <td><input type='text' name='state' value='$ah{state}'></td>
378 <td><input type='text' name='country' value='$ah{country}'></td>
382 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
385 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
386 <input type='hidden' name='addr_type' value='$a'>
387 <input type='hidden' name='id' value='$node'>
388 <input type='submit' name='action' value='Save Address'>
394 print "<tr></table><hr><h2>New Child</h2>";
396 print "<form method='POST'>".
397 "<table class='table_class'>\n";
401 td("<input type='text' name='name'>"),
404 th($org_cols{shortname}),
405 td("<input type='text' name='shortname'>"),
408 th($org_cols{ou_type}),
409 td("<select name='ou_type'>".do{
410 my $out = '<option>-- Select One --</option>';
411 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
412 $out .= "<option value='$type'>".$type->name.'</option>'
418 th($org_cols{email}),
419 td("<input type='text' name='email'>"),
422 th($org_cols{phone}),
423 td("<input type='text' name='phone'>"),
426 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
427 "<input type='submit' name='action' value='Add New'/></td>" );
428 print "</table></form><hr/>";
433 print "</div></body></html>";