4 use OpenILS::Application::Storage;
5 use OpenILS::Application::Storage::CDBI;
7 # I need to abstract the driver loading away...
8 use OpenILS::Application::Storage::Driver::Pg;
10 use CGI qw/:standard start_*/;
14 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr},$config{pw});
15 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
19 #-------------------------------------------------------------------------------
21 #-------------------------------------------------------------------------------
23 my %org_cols = ( qw/id SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName/ );
25 my @col_display_order = ( qw/id name shortname ou_type parent_ou/ );
27 if (my $action = $cgi->param('action')) {
28 if ( $action eq 'Update' ) {
29 for my $id ( ($cgi->param('id')) ) {
30 my $u = actor::org_unit->retrieve($id);
31 for my $col ( keys %org_cols ) {
32 next if ($cgi->param($col."_$id") =~ /Select One/o);
33 $u->$col( $cgi->param($col."_$id") );
37 } elsif ( $action eq 'Add New' ) {
38 actor::org_unit->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
39 } elsif ( $action eq 'Save Address' ) {
40 my $org = actor::org_unit->retrieve($cgi->param('id'));
44 $$addr{org_unit} = $cgi->param('org_unit') || $org->id;
45 $$addr{street1} = $cgi->param('street1');
46 $$addr{street2} = $cgi->param('street2');
47 $$addr{city} = $cgi->param('city');
48 $$addr{county} = $cgi->param('county');
49 $$addr{state} = $cgi->param('state');
50 $$addr{country} = $cgi->param('country');
51 $$addr{post_code} = $cgi->param('post_code');
53 my $a_type = $cgi->param('addr_type');
56 my $a = actor::org_address->retrieve($cgi->param('aid'));
60 next unless $$addr{$_};
65 $a = actor::org_address->create( {map {defined($$addr{$_}) ? ($_ => $$addr{$_}) : ()} keys %$addr} );
68 $org->$a_type($a->id);
73 #-------------------------------------------------------------------------------
75 #-------------------------------------------------------------------------------
78 Content-type: text/html
85 border: dashed lightgrey 1px;
86 background-color: #EEE;
87 border-collapse: collapse;
99 border: solid lightgrey 1px;
103 background-color: lightblue;
104 border: solid blue 1px;
109 /*--------------------------------------------------|
110 | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
111 |---------------------------------------------------|
112 | Copyright (c) 2002-2003 Geir Landrö |
113 |--------------------------------------------------*/
116 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
123 vertical-align: middle;
127 text-decoration: none;
129 .dtree a.node, .dtree a.nodeSel {
131 padding: 1px 2px 1px 2px;
133 .dtree a.node:hover, .dtree a.nodeSel:hover {
135 text-decoration: underline;
138 background-color: #c0d2ec;
146 <script language='javascript' src='support/dtree.js'></script>
149 <body style='padding: 25px;'>
151 <a href="$config{index}">Home</a>
153 <h1>Library Hierarchy Setup</h1>
157 my $uri = $cgi->url(-relative=>1);
160 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
161 my $name = $lib->name;
165 <div style="float: left;">
166 <script language='javascript'>
167 var tree = new dTree("tree");
168 tree.add($lib, -1, "$name", "$uri?action=child&id=$lib", "$name");
174 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'name'} ) ) {
175 my $name = $lib->name;
177 my $parent = $lib->parent_ou;
178 print "\ttree.add($lib, $parent, \"$name\", \"$uri?action=child&id=$lib\", \"$name\");\n";
182 tree.closeAllChildren($top);
183 document.write(tree.toString());
190 #-------------------------------------------------------------------------------
192 #-------------------------------------------------------------------------------
194 if (my $action = $cgi->param('action')) {
195 if ( $action eq 'child' ) {
196 my $id = $cgi->param('id');
198 my $node = actor::org_unit->retrieve($id);
199 #-----------------------------------------------------------------------
201 #-----------------------------------------------------------------------
203 print "<h2>Edit ".$node->name."</h2>";
204 print "<form method='POST'>".
205 "<table class='table_class'><tr class='header_class'>\n";
213 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
216 th($org_cols{shortname}),
217 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
220 th($org_cols{ou_type}),
221 td("<select name='ou_type_$node'>".do{
222 my $out = '<option>-- Select One --</option>';
223 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
224 $out .= "<option value='$type' ".do {
225 if ($node->ou_type == $type->id) {
227 }}.'>'.$type->name.'</option>'
233 th($org_cols{parent_ou}),
234 td("<select name='parent_ou_$node'>".do{
235 my $out = '<option>-- Select One --</option>';
236 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
237 $out .= "<option value='$org' ".do {
238 if ($node->parent_ou == $org->id) {
240 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
243 }."</select><input type='hidden' value='$node' name='id'>"),
246 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
248 print "</table></form><hr/><table cellspacing='20'><tr>";
251 #-------------------------------------------------------------------------
253 #-------------------------------------------------------------------------
255 my %addrs = ( ill_address => 'ILL Address',
256 holds_address => 'Consortial Holds Address',
257 mailing_address => 'Mailing Address',
258 billing_address => 'Physical Address'
260 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
261 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
263 my %ah = ( street1 => $addr?$addr->street1:'',
264 street2 => $addr?$addr->street2:'',
265 city => $addr?$addr->city:'',
266 county => $addr?$addr->county:'',
267 state => $addr?$addr->state:'',
268 country => $addr?$addr->country:'US',
269 post_code => $addr?$addr->post_code:'',
270 org_unit => $addr?$addr->org_unit:$node->id,
271 id => $addr?$addr->id:'',
274 print '</tr><tr>' if ($a eq 'holds_address');
279 <table class='table_class'>
281 <th colspan=2>$addrs{$a}</th>
285 <td><input type='text' name='aid' value='$ah{id}'></td>
289 <td><input type='text' name='street1' value='$ah{street1}'></td>
293 <td><input type='text' name='street2' value='$ah{street2}'></td>
297 <td><input type='text' name='city' value='$ah{city}'></td>
301 <td><input type='text' name='county' value='$ah{county}'></td>
305 <td><input type='text' name='state' value='$ah{state}'></td>
309 <td><input type='text' name='country' value='$ah{country}'></td>
313 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
316 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
317 <input type='hidden' name='addr_type' value='$a'>
318 <input type='hidden' name='id' value='$node'>
319 <input type='submit' name='action' value='Save Address'>
325 print "<tr></table><hr><h2>New Child</h2>";
327 print "<form method='POST'>".
328 "<table class='table_class'>\n";
332 td("<input type='text' name='name'>"),
335 th($org_cols{shortname}),
336 td("<input type='text' name='shortname'>"),
339 th($org_cols{ou_type}),
340 td("<select name='ou_type'>".do{
341 my $out = '<option>-- Select One --</option>';
342 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
343 $out .= "<option value='$type'>".$type->name.'</option>'
348 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
349 "<input type='submit' name='action' value='Add New'/></td>" );
350 print "</table></form><hr/>";
355 print "</div></body></html>";