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 <script language='javascript' src='/js/widgets/xtree.js'></script>
112 <body style='padding: 25px;'>
114 <a href="$config{index}">Home</a>
116 <h1>Library Hierarchy Setup</h1>
120 my $uri = $cgi->url(-relative=>1);
123 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
124 my $name = $lib->name;
127 <div style="float: left;">
128 <script language='javascript'>
130 function getById (id) { return document.getElementById(id); }
131 function createAppElement (el) { return document.createElement(el); }
132 function createAppTextNode (txt) { return document.createTextNode(txt); }
134 var node_$lib = new WebFXTree('$name','$uri?action=child&id=$lib');
140 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'id'} ) ) {
141 my $name = $lib->name;
143 my $parent = $lib->parent_ou;
145 var node_$lib = new WebFXTreeItem('$name','$uri?action=child&id=$lib');
147 }for my $lib ( sort {$a->name cmp $b->name} actor::org_unit->retrieve_all ) {
148 my $parent = $lib->parent_ou;
151 node_$parent.add(node_$lib);
156 document.write(node_$top);
163 #-------------------------------------------------------------------------------
165 #-------------------------------------------------------------------------------
167 if (my $action = $cgi->param('action')) {
168 if ( $action eq 'child' ) {
169 my $id = $cgi->param('id');
171 my $node = actor::org_unit->retrieve($id);
172 #-----------------------------------------------------------------------
174 #-----------------------------------------------------------------------
176 print "<h2>Edit ".$node->name."</h2>";
177 print "<form method='POST'>".
178 "<table class='table_class'><tr class='header_class'>\n";
186 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
189 th($org_cols{shortname}),
190 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
193 th($org_cols{ou_type}),
194 td("<select name='ou_type_$node'>".do{
195 my $out = '<option>-- Select One --</option>';
196 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
197 $out .= "<option value='$type' ".do {
198 if ($node->ou_type == $type->id) {
200 }}.'>'.$type->name.'</option>'
206 th($org_cols{parent_ou}),
207 td("<select name='parent_ou_$node'>".do{
208 my $out = '<option>-- Select One --</option>';
209 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
210 $out .= "<option value='$org' ".do {
211 if ($node->parent_ou == $org->id) {
213 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
216 }."</select><input type='hidden' value='$node' name='id'>"),
219 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
221 print "</table></form><hr/><table cellspacing='20'><tr>";
224 #-------------------------------------------------------------------------
226 #-------------------------------------------------------------------------
228 my %addrs = ( ill_address => 'ILL Address',
229 holds_address => 'Consortial Holds Address',
230 mailing_address => 'Mailing Address',
231 billing_address => 'Physical Address'
233 for my $a (qw/billing_address mailing_address holds_address ill_address/) {
234 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
236 my %ah = ( street1 => $addr?$addr->street1:'',
237 street2 => $addr?$addr->street2:'',
238 city => $addr?$addr->city:'',
239 county => $addr?$addr->county:'',
240 state => $addr?$addr->state:'',
241 country => $addr?$addr->country:'US',
242 post_code => $addr?$addr->post_code:'',
243 org_unit => $addr?$addr->org_unit:$node->id,
244 id => $addr?$addr->id:'',
247 print '</tr><tr>' if ($a eq 'holds_address');
252 <table class='table_class'>
254 <th colspan=2>$addrs{$a}</th>
258 <td><input type='text' name='aid' value='$ah{id}'></td>
262 <td><input type='text' name='street1' value='$ah{street1}'></td>
266 <td><input type='text' name='street2' value='$ah{street2}'></td>
270 <td><input type='text' name='city' value='$ah{city}'></td>
274 <td><input type='text' name='county' value='$ah{county}'></td>
278 <td><input type='text' name='state' value='$ah{state}'></td>
282 <td><input type='text' name='country' value='$ah{country}'></td>
286 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
289 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
290 <input type='hidden' name='addr_type' value='$a'>
291 <input type='hidden' name='id' value='$node'>
292 <input type='submit' name='action' value='Save Address'>
298 print "<tr></table><hr><h2>New Child</h2>";
300 print "<form method='POST'>".
301 "<table class='table_class'>\n";
305 td("<input type='text' name='name'>"),
308 th($org_cols{shortname}),
309 td("<input type='text' name='shortname'>"),
312 th($org_cols{ou_type}),
313 td("<select name='ou_type'>".do{
314 my $out = '<option>-- Select One --</option>';
315 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
316 $out .= "<option value='$type'>".$type->name.'</option>'
321 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
322 "<input type='submit' name='action' value='Add New'/></td>" );
323 print "</table></form><hr/>";
328 print "</div></body></html>";