2 # for each supported locale, turn the orgTree and orgTypes into a static HTML option list
4 use OpenSRF::AppSession;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenSRF::Utils::SettingsClient;
8 use OpenILS::Application::AppUtils;
9 use Unicode::Normalize;
13 die "usage: perl org_tree_html_options.pl <bootstrap_config> <output_path> <output_file>" unless $ARGV[2];
14 OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
17 my $filename = $ARGV[2];
21 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
23 #Get our list of locales
24 my $session = OpenSRF::AppSession->create("open-ils.cstore");
25 my $locales = $session->request("open-ils.cstore.direct.config.i18n_locale.search.atomic", {"code" => {"!=" => undef}}, {"order_by" => {"i18n_l" => "name"}})->gather();
26 $session->disconnect();
28 foreach my $locale (@$locales) {
29 my $ses = OpenSRF::AppSession->create("open-ils.actor");
30 $ses->session_locale($locale->code);
31 my $tree = $ses->request("open-ils.actor.org_tree.retrieve")->gather(1);
33 my $aout = $ses->request("open-ils.actor.org_types.retrieve")->gather(1);
34 foreach my $type (@$aout) {
35 $types[int($type->id)] = $type;
37 my $dir = File::Spec->catdir($path, $locale->code);
39 mkdir($dir) or die "Could not create output directory: $dir $!\n";
43 print_option($tree, \@org_tree_html);
45 open(FILE, '>', File::Spec->catfile($dir, $filename)) or die $!;
46 print FILE @org_tree_html;
52 my $org_tree_html = shift;
54 return unless ($node->opac_visible =~ /^[y1t]+/i);
56 my $depth = $types[$node->ou_type]->depth;
57 my $sname = OpenILS::Application::AppUtils->entityize($node->shortname);
58 my $name = OpenILS::Application::AppUtils->entityize($node->name);
59 my $kids = $node->children;
61 push @$org_tree_html, "<option value='$sname'>" . '   'x$depth . "$name</option>\n";
62 print_option($_, $org_tree_html) for (@$kids);