6 use OpenILS::Application::Storage;
7 use OpenILS::Application::Storage::CDBI;
9 # I need to abstract the driver loading away...
10 use OpenILS::Application::Storage::Driver::Pg;
12 use CGI qw/:standard start_*/;
14 do '##CONFIG##/live-db-setup.pl';
15 #do '/openils/conf/live-db-setup.pl';
17 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
18 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
23 #-------------------------------------------------------------------------------
25 #-------------------------------------------------------------------------------
27 my %org_cols = ( qw/id SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName email Email phone Phone opac_visible OPACVisible/ );
29 my @col_display_order = ( qw/id name shortname ou_type email phone opac_visible parent_ou/ );
31 if (my $action = $cgi->param('action')) {
32 if ( $action eq 'Update' ) {
33 for my $id ( ($cgi->param('id')) ) {
34 my $u = actor::org_unit->retrieve($id);
35 for my $col ( keys %org_cols ) {
36 next if ($cgi->param($col."_$id") =~ /Select One/o);
37 if ($col eq 'shortname') {
38 $u->$col( uc( $cgi->param($col."_$id") ) );
40 $u->$col( $cgi->param($col."_$id") );
45 } elsif ( $action eq 'Update Hours' ) {
46 for my $id ( ($cgi->param('id')) ) {
47 my $hoo = actor::org_unit::hours_of_operation->retrieve($id);
48 for my $col ( $hoo->columns('Essential') ) {
49 $hoo->$col( $cgi->param($col) );
53 } elsif ( $action eq 'Add New' ) {
54 actor::org_unit->create(
56 defined($cgi->param($_)) ?
58 ($_ => uc($cgi->param($_))) :
59 ($_ => $cgi->param($_))
65 } elsif ( $action eq 'Save Address' ) {
66 my $org = actor::org_unit->retrieve($cgi->param('id'));
70 $$addr{org_unit} = $cgi->param('org_unit') || $org->id;
71 $$addr{street1} = $cgi->param('street1');
72 $$addr{street2} = $cgi->param('street2');
73 $$addr{city} = $cgi->param('city');
74 $$addr{county} = $cgi->param('county');
75 $$addr{state} = $cgi->param('state');
76 $$addr{country} = $cgi->param('country');
77 $$addr{post_code} = $cgi->param('post_code');
79 my $a_type = $cgi->param('addr_type');
82 my $a = actor::org_address->retrieve($cgi->param('aid'));
86 next unless $$addr{$_};
91 $a = actor::org_address->create( {map {defined($$addr{$_}) ? ($_ => $$addr{$_}) : ()} keys %$addr} );
94 $org->$a_type($a->id);
99 #-------------------------------------------------------------------------------
101 #-------------------------------------------------------------------------------
104 Content-type: text/html
109 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
110 <meta http-equiv="Pragma" content="no-cache" />
111 <meta http-equiv="Expires" content="Thu, 01 Dec 2000 16:00:00 GMT" />
114 border: dashed lightgrey 1px;
115 background-color: #EEE;
116 border-collapse: collapse;
128 border: solid lightgrey 1px;
132 background-color: lightblue;
133 border: solid blue 1px;
138 /*--------------------------------------------------|
139 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
140 |---------------------------------------------------|
141 | Copyright (c) 2002-2003 Geir Landrö |
142 |--------------------------------------------------*/
145 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
152 vertical-align: middle;
156 text-decoration: none;
158 .dtree a.node, .dtree a.nodeSel {
160 padding: 1px 2px 1px 2px;
162 .dtree a.node:hover, .dtree a.nodeSel:hover {
164 text-decoration: underline;
167 background-color: #c0d2ec;
175 <script language='javascript' src='support/dtree.js'></script>
178 <body style='padding: 25px;'>
180 <a href="$config{index}">Home</a>
182 <h1>Library Hierarchy Setup</h1>
186 my $uri = $cgi->url(-relative=>1);
189 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
190 my $name = $lib->name;
195 <script language='javascript'>
196 var tree = new dTree("tree");
197 tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
203 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'name'} ) ) {
204 my $name = $lib->name;
206 my $parent = $lib->parent_ou;
207 print "\ttree.add($lib, $parent, \"$name\", \"$uri?action=child&id=$lib\", \"$name\");\n";
211 tree.closeAllChildren($top);
212 document.write(tree.toString());
219 #-------------------------------------------------------------------------------
221 #-------------------------------------------------------------------------------
223 if (my $action = $cgi->param('action')) {
224 if ( $action eq 'child' ) {
225 my $id = $cgi->param('id');
227 my $node = actor::org_unit->retrieve($id);
228 #-----------------------------------------------------------------------
230 #-----------------------------------------------------------------------
232 print "<hr/><h2>Edit ".$node->name."</h2>";
233 print "<form method='POST'>".
234 "<table class='table_class'><tr class='header_class'>\n";
242 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
245 th($org_cols{shortname}),
246 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
249 th($org_cols{ou_type}),
250 td("<select name='ou_type_$node'>".do{
251 my $out = '<option>-- Select One --</option>';
252 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
253 $out .= "<option value='$type' ".do {
254 if ($node->ou_type == $type->id) {
256 }}.'>'.$type->name.'</option>'
262 th($org_cols{email}),
263 td("<input type='text' name='email_$node' value=\"". $node->email() ."\">"),
267 th($org_cols{phone}),
268 td("<input type='text' name='phone_$node' value='". $node->phone() ."'>"),
272 th($org_cols{opac_visible} .'<span style="color:red">*</span>'),
273 td("<select name='opac_visible_$node'>".
275 my $out = "<option value='t' ";
276 $out .= ($node->opac_visible =~ /^[y1t]+/i) ? "selected='yes'" : "";
277 $out .= ">True</option><option value='f' ";
278 $out .= ($node->opac_visible =~ /^[n0f]+/i) ? "selected='yes'" : "";
279 $out .= ">False</option>";
286 th($org_cols{parent_ou}),
287 td("<select name='parent_ou_$node'>".do{
288 my $out = '<option>-- Select One --</option>';
289 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
290 $out .= "<option value='$org' ".do {
291 if ($node->parent_ou == $org->id) {
293 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
296 }."</select><input type='hidden' value='$node' name='id'>"),
299 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
300 print "</table><span style='color:red;'>*</span>".
301 "You must hide every OU you want hidden, not just an ancestor!</form>";
303 #-------------------------------------------------------------------------
304 # Hours of operation form
305 #-------------------------------------------------------------------------
319 print "<hr/><h2>Hours of Operation for ".$node->name."</h2>".
320 "<form method='POST'>".
321 "<table class='table_class'><tr class='header_class'>\n";
329 my $hoo = actor::org_unit::hours_of_operation->find_or_create( { id => $node->id } );
330 for my $day ( 0 .. 6 ) {
331 my $open = "dow_${day}_open";
332 my $close = "dow_${day}_close";
336 td("<input type='text' name='$open' value=\"". $hoo->$open ."\">"),
337 td("<input type='text' name='$close' value=\"". $hoo->$close ."\">"),
341 print Tr( "<td colspan='3'>".
342 "<input type='hidden' value='$node' name='id'>".
343 "<input type='submit' name='action' value='Update Hours'/></td>"
345 print "</table></form>";
348 #-------------------------------------------------------------------------
350 #-------------------------------------------------------------------------
352 print "<hr/><h2>Addresses for ".$node->name."</h2>";
353 print "<table cellspacing='20'><tr>";
354 my %addrs = ( ill_address => 'ILL Address',
355 holds_address => 'Consortial Holds Address',
356 mailing_address => 'Mailing Address',
357 billing_address => 'Physical Address'
359 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
360 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
362 my %ah = ( street1 => $addr?$addr->street1:'',
363 street2 => $addr?$addr->street2:'',
364 city => $addr?$addr->city:'',
365 county => $addr?$addr->county:'',
366 state => $addr?$addr->state:'',
367 country => $addr?$addr->country:'US',
368 post_code => $addr?$addr->post_code:'',
369 org_unit => $addr?$addr->org_unit:$node->id,
370 id => $addr?$addr->id:'',
373 #print '</tr><tr>' if ($a eq 'holds_address');
378 <table class='table_class'>
380 <th colspan=2>$addrs{$a}</th>
384 <td><input type='text' name='aid' value='$ah{id}'></td>
388 <td><input type='text' name='street1' value='$ah{street1}'></td>
392 <td><input type='text' name='street2' value='$ah{street2}'></td>
396 <td><input type='text' name='city' value='$ah{city}'></td>
400 <td><input type='text' name='county' value='$ah{county}'></td>
404 <td><input type='text' name='state' value='$ah{state}'></td>
408 <td><input type='text' name='country' value='$ah{country}'></td>
412 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
415 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
416 <input type='hidden' name='addr_type' value='$a'>
417 <input type='hidden' name='id' value='$node'>
418 <input type='submit' name='action' value='Save Address'>
424 print "<tr></table><hr><h2>New Child</h2>";
426 print "<form method='POST'>".
427 "<table class='table_class'>\n";
431 td("<input type='text' name='name'>"),
434 th($org_cols{shortname}),
435 td("<input type='text' name='shortname'>"),
438 th($org_cols{ou_type}),
439 td("<select name='ou_type'>".do{
440 my $out = '<option>-- Select One --</option>';
441 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
442 $out .= "<option value='$type'>".$type->name.'</option>'
448 th($org_cols{email}),
449 td("<input type='text' name='email'>"),
452 th($org_cols{phone}),
453 td("<input type='text' name='phone'>"),
456 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
457 "<input type='submit' name='action' value='Add New'/></td>" );
458 print "</table></form><hr/>";
463 print "</div></body></html>";