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});
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('org_unit'));
44 $$addr{org_unit} = $cgi->param('org_unit');
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 $a_type = $cgi->param('addr_type');
56 my $a = actor::org_address->retrieve($cgi->param('id'));
59 $a->$_($$addr{$_}) for (keys %$addr);
62 $a = actor::org_unit->create( $addr );
65 $org->$a_type($a->id);
70 #-------------------------------------------------------------------------------
72 #-------------------------------------------------------------------------------
75 Content-type: text/html
82 border: dashed lightgrey 1px;
83 background-color: #EEE;
84 border-collapse: collapse;
96 border: solid lightgrey 1px;
100 background-color: lightblue;
101 border: solid blue 1px;
106 <script language='javascript' src='/js/widgets/xtree.js'></script>
109 <body style='padding: 25px;'>
111 <a href="$config{index}">Home</a>
113 <h1>Library Hierarchy Setup</h1>
117 my $uri = $cgi->url(-relative=>1);
120 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
121 my $name = $lib->name;
124 <div style="float: left;">
125 <script language='javascript'>
127 function getById (id) { return document.getElementById(id); }
128 function createAppElement (el) { return document.createElement(el); }
129 function createAppTextNode (txt) { return document.createTextNode(txt); }
131 var node_$lib = new WebFXTree('$name','$uri?action=child&id=$lib');
137 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'id'} ) ) {
138 my $name = $lib->name;
140 my $parent = $lib->parent_ou;
142 var node_$lib = new WebFXTreeItem('$name','$uri?action=child&id=$lib');
144 }for my $lib ( sort {$a->name cmp $b->name} actor::org_unit->retrieve_all ) {
145 my $parent = $lib->parent_ou;
148 node_$parent.add(node_$lib);
153 document.write(node_$top);
160 #-------------------------------------------------------------------------------
162 #-------------------------------------------------------------------------------
164 if (my $action = $cgi->param('action')) {
165 if ( $action eq 'child' ) {
166 my $id = $cgi->param('id');
168 my $node = actor::org_unit->retrieve($id);
169 #-----------------------------------------------------------------------
171 #-----------------------------------------------------------------------
173 print "<h2>Edit ".$node->name."</h2>";
174 print "<form method='POST'>".
175 "<table class='table_class'><tr class='header_class'>\n";
183 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
186 th($org_cols{shortname}),
187 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
190 th($org_cols{ou_type}),
191 td("<select name='ou_type_$node'>".do{
192 my $out = '<option>-- Select One --</option>';
193 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
194 $out .= "<option value='$type' ".do {
195 if ($node->ou_type == $type->id) {
197 }}.'>'.$type->name.'</option>'
203 th($org_cols{parent_ou}),
204 td("<select name='parent_ou_$node'>".do{
205 my $out = '<option>-- Select One --</option>';
206 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
207 $out .= "<option value='$org' ".do {
208 if ($node->parent_ou == $org->id) {
210 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
213 }."</select><input type='hidden' value='$node' name='id'>"),
216 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
218 print "</table></form><hr/>";
221 #-------------------------------------------------------------------------
223 #-------------------------------------------------------------------------
225 my %addrs = ( ill_address => 'ILL Address',
226 holds_address => 'Consortial Holds Address',
227 mailing_address => 'Mailing Address',
228 billing_address => 'Physical Address'
230 for my $a (keys %addrs) {
231 my $addr = actor::org_address->retrieve( $node->$a ) if ($node->$a);
233 my %ah = ( street1 => $addr?$addr->street1:'',
234 street2 => $addr?$addr->street2:'',
235 city => $addr?$addr->city:'',
236 county => $addr?$addr->count:'',
237 state => $addr?$addr->state:'',
238 country => $addr?$addr->country:'US',
239 post_code => $addr?$addr->post_code:'',
240 org_unit => $addr?$addr->org_unit:'',
241 id => $addr?$addr->id:'',
247 <table class='table_class'>
249 <th colspan=2>$addrs{$a}</th>
253 <td><input type='text' name='street1' value='$ah{street1}'></td>
257 <td><input type='text' name='street2' value='$ah{street2}'></td>
261 <td><input type='text' name='city' value='$ah{city}'></td>
265 <td><input type='text' name='county' value='$ah{county}'></td>
269 <td><input type='text' name='state' value='$ah{state}'></td>
273 <td><input type='text' name='country' value='$ah{country}'></td>
277 <td><input type='text' name='post_code' value='$ah{post_code}'></td>
280 <input type='hidden' name='org_unit' value='$ah{org_unit}'>
281 <input type='hidden' name='id' value='$ah{id}'>
282 <input type='hidden' name='addr_type' value='$a'>
283 <input type='submit' name='action' value='Save Address'>
289 print "<h2>New Child</h2>";
291 print "<form method='POST'>".
292 "<table class='table_class'>\n";
296 td("<input type='text' name='name'>"),
299 th($org_cols{shortname}),
300 td("<input type='text' name='shortname'>"),
303 th($org_cols{ou_type}),
304 td("<select name='ou_type'>".do{
305 my $out = '<option>-- Select One --</option>';
306 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
307 $out .= "<option value='$type'>".$type->name.'</option>'
312 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
313 "<input type='submit' name='action' value='Add New'/></td>" );
314 print "</table></form><hr/>";
319 print "</div></body></html>";