used decomposed characters -- mostly for consistency with other recent changes
[Evergreen.git] / Open-ILS / src / extras / org_tree_html_options.pl
1 #!/usr/bin/perl
2 # turns the orgTree and orgTypes into a static HTML option list
3
4 use OpenSRF::AppSession;
5 use OpenSRF::System;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenSRF::Utils::SettingsClient;
8 use Unicode::Normalize;
9
10 die "usage: perl org_tree_html_options.pl <bootstrap_config> <output_file>" unless $ARGV[1];
11 OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
12
13 open FILE, ">$ARGV[1]";
14
15 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
16
17 my $ses = OpenSRF::AppSession->create("open-ils.actor");
18 my $tree = $ses->request("open-ils.actor.org_tree.retrieve")->gather(1);
19
20 print_option($tree);
21
22 $ses->disconnect();
23 close FILE;
24
25
26
27 sub print_option {
28         my $node = shift;
29         return unless ($node->opac_visible =~ /^[y1t]+/i);
30
31         my $depth = $node->ou_type - 1;
32         my $sname = entityize($node->shortname);
33         my $name = entityize($node->name);
34         my $kids = $node->children;
35
36         print FILE "<option value='$sname'>" . '&#160;&#160;&#160;'x$depth . "$name</option>\n";
37         print_option($_) for (@$kids);
38 }
39
40 sub entityize {
41         my $stuff = shift || return "";
42         $stuff =~ s/\</&lt;/og;
43         $stuff =~ s/\>/&gt;/og;
44         $stuff =~ s/\&/&amp;/og;
45         $stuff = NFD($stuff);
46         $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
47         return $stuff;
48 }
49