1 package OpenILS::Utils::Configure;
6 use OpenILS::Utils::Cronscript;
11 my $core = OpenILS::Utils::Cronscript->new({nolockfile => 1});
15 my $map = $Fieldmapper::fieldmap;
17 # if a true value is provided, we generate the web (light) version of the fieldmapper
18 if(!$web) { $web = ""; }
21 aou au perm_ex ex aout
22 mvr ccs ahr aua ac actscecm cbreb acpl
23 cbrebi acpn acp acnn acn bren asc asce
24 clfm cifm citm cam ahtc
27 crcd crmf crrf mbts aoc aus
28 mous mobts mb ancc cnct cnal
31 my @reports = qw/ perm_ex ex ao aou aout /;
34 $output = "var _c = {};\n";
36 for my $object (keys %$map) {
38 my $hint = $map->{$object}->{hint};
40 if($web eq "web_core") {
41 next unless (grep { $_ eq $hint } @web_core );
44 if($web eq "reports") {
45 next unless (grep { $_ eq $hint } @web_core );
49 my $short_name = $map->{$object}->{hint};
52 for my $field (keys %{$map->{$object}->{fields}}) {
53 my $position = $map->{$object}->{fields}->{$field}->{position};
54 $fields[$position] = $field;
57 $output .= "_c[\"$short_name\"] = [";
60 if( $f ne "isnew" and $f ne "ischanged" and $f ne "isdeleted" ) {
69 $output .= "var fmclasses = _c;\n";
74 # ------------------------------------------------------------
75 # turns the orgTree and orgTypes into js files
76 # ------------------------------------------------------------
77 use OpenSRF::Utils::Cache;
82 my $core = OpenILS::Utils::Cronscript->new({nolockfile => 1});
85 # must be loaded after the IDL is parsed
86 require OpenILS::Utils::CStoreEditor;
88 # Get our list of locales
89 my $locales = get_locales();
91 foreach my $locale (@$locales) {
92 warn "removing OrgTree from the cache for locale " . $locale->code . "...\n";
93 my $cache = OpenSRF::Utils::Cache->new;
94 $cache->delete_cache("orgtree.".$locale->code);
96 # fetch the org_unit's and org_unit_type's
97 my $e = OpenILS::Utils::CStoreEditor->new;
99 $e->session->session_locale($locale->code) if ($locale->code);
101 my $types = $e->retrieve_all_actor_org_unit_type;
102 my $tree = $e->request(
103 'open-ils.cstore.direct.actor.org_unit.search.atomic',
104 {id => {"!=" => undef}},
105 {order_by => {aou => 'name'}, no_i18n => $locale->code ? 0 : 1 }
107 my $dir = File::Spec->catdir($path, $locale->code);
111 build_tree_js($types, $tree, File::Spec->catfile($dir, $filename));
117 return 'null' unless defined $v;
119 # required for JS code this is checking truthness
120 # without using isTrue() (1/0 vs. t/f)
121 return 1 if $v eq 't';
122 return 0 if $v eq 'f';
124 $v =~ s/([\x{0080}-\x{fffd}])/sprintf('\u%04x',ord($1))/sgoe;
134 my $pile = "var _l = [";
138 my ($i,$t,$p,$n,$v,$s) = ($o->id,$o->ou_type,$o->parent_ou,val($o->name),val($o->opac_visible),val($o->shortname));
140 push @array, "[$i,$t,$p,$n,$v,$s]";
143 $pile .= join ',', @array;
144 $pile .= "]; /* Org Units */ \n";
146 $pile .= 'var globalOrgTypes = [';
147 for my $t (@$types) {
148 my ($u,$v,$d,$i,$n,$o,$p) = (val($t->can_have_users),val($t->can_have_vols),$t->depth,$t->id,val($t->name),val($t->opac_label),$t->parent);
150 $pile .= "new aout([null,$u,$v,$d,$i,$n,$o,$p]), ";
152 $pile =~ s/, $//; # remove trailing comma
153 $pile .= ']; /* OU Types */';
155 open(OUTFH, '>', $outfile) or die "Could not open $outfile : $!";
156 print OUTFH "$pile\n";
160 sub org_tree_html_options {
161 # for each supported locale, turn the orgTree and orgTypes into a static HTML option list
163 use Unicode::Normalize;
167 my $filename = shift;
171 my $core = OpenILS::Utils::Cronscript->new({nolockfile => 1});
174 my $locales = get_locales();
176 foreach my $locale (@$locales) {
177 my $ses = OpenSRF::AppSession->create("open-ils.actor");
178 $ses->session_locale($locale->code);
179 my $tree = $ses->request("open-ils.actor.org_tree.retrieve")->gather(1);
181 my $aout = $ses->request("open-ils.actor.org_types.retrieve")->gather(1);
182 foreach my $type (@$aout) {
183 $types[int($type->id)] = $type;
185 my $dir = File::Spec->catdir($path, $locale->code);
187 mkdir($dir) or die "Could not create output directory: $dir $!\n";
191 print_org_tree_html($tree, \@org_tree_html, \@types);
194 open(OUTFH, '>', File::Spec->catfile($dir, $filename)) or die $!;
195 print OUTFH @org_tree_html;
201 sub print_org_tree_html {
203 my $org_tree_html = shift;
206 return unless ($node->opac_visible =~ /^[y1t]+/i);
208 my $depth = $types->[$node->ou_type]->depth;
209 my $sname = OpenILS::Application::AppUtils->entityize($node->shortname);
210 my $name = OpenILS::Application::AppUtils->entityize($node->name);
211 my $kids = $node->children;
213 push @$org_tree_html, "<option value='$sname'>" . '   'x$depth . "$name</option>\n";
214 print_org_tree_html($_, $org_tree_html, $types) for (@$kids);
218 # Renders a JavaScript version of the org unit search groups
220 my $core = OpenILS::Utils::Cronscript->new({nolockfile => 1});
223 # must be loaded after the IDL is parsed
224 require OpenILS::Utils::CStoreEditor;
228 # fetch the org_unit's and org_unit_type's
229 my $e = OpenILS::Utils::CStoreEditor->new;
231 my $lassos = $e->request(
232 'open-ils.cstore.direct.actor.org_lasso.search.atomic',
233 {id => {"!=" => undef}},
234 {order_by => {lasso => 'name'}}
237 # We need at least one defined search group; otherwise, just generate an empty array
238 if (scalar(@$lassos) > 0) {
240 "var _lasso = [\n new lasso(" .
241 join( "),\n new lasso(", map { OpenSRF::Utils::JSON->perl2JSON( bless($_, 'ARRAY') ) } @$lassos ) .
242 ")\n]; /* Org Search Groups (Lassos) */ \n";
246 ]; /* Org Search Groups (Lassos) */
253 sub locale_html_options {
254 # Turns supported locales into a static HTML option list
255 my $locales = get_locales();
257 my $output = "<select name='locale'>\n";
258 foreach my $locale (@$locales) {
259 my $code = OpenILS::Application::AppUtils->entityize($locale->code);
260 my $name = OpenILS::Application::AppUtils->entityize($locale->name);
261 $output .= " <option value='$code'>$name</option>\n";
263 $output .= "</select>\n";
269 # ------------------------------------------------------------
270 # turns the facet fields defined on config.metabib_field into JS
271 # ------------------------------------------------------------
274 my $filename = shift;
275 # Get our list of locales
276 my $locales = get_locales();
278 foreach my $locale (@$locales) {
279 warn "removing facet list from the cache for locale " . $locale->code . "...\n";
280 my $cache = OpenSRF::Utils::Cache->new;
281 $cache->delete_cache("facet_definition.".$locale->code);
283 # fetch the org_unit's and org_unit_type's
284 my $e = OpenILS::Utils::CStoreEditor->new;
286 $e->session->session_locale($locale->code) if ($locale->code);
288 my $types = $e->retrieve_all_actor_org_unit_type;
289 my $tree = $e->request(
290 'open-ils.cstore.direct.config.metabib_field.search.atomic',
291 { facet_field => 't' },
292 { no_i18n => $locale->code ? 0 : 1,
294 flesh_fields => { cmf => [ 'field_class' ] }
297 my $dir = File::Spec->catdir($path, $locale->code);
301 build_facet_type_js($tree, File::Spec->catfile($dir, $filename));
305 sub build_facet_type_js {
309 my $pile = "var globalFacets = {";
314 name => val($o->name),
315 label => val($o->label),
316 classname => val($o->field_class->name),
317 classlabel => val($o->field_class->label)
320 $pile .= $hash{id}.':{'.join(',', map { "$_:$hash{$_}" } keys %hash).'},';
323 $pile =~ s/,$//; # remove trailing comma
324 $pile .= "}; /* Facets */";
326 open(OUTFH, '>', $outfile) or die "Could not open $outfile : $!";
327 print OUTFH "$pile\n";
331 sub org_tree_proximity {
332 # calculate the proximity of organizations in the organization tree
334 my $session = OpenILS::Utils::Cronscript->new({nolockfile => 1})->session('open-ils.storage');
335 my $result = $session->request("open-ils.storage.actor.org_unit.refresh_proximity");
338 print "Successfully updated the organization proximity\n";
340 print "Failed to update the organization proximity\n";
342 $session->disconnect();
346 # Get our list of locales
347 my $session = OpenILS::Utils::Cronscript->new({nolockfile => 1})->session("open-ils.cstore");
348 my $locales = $session->request(
349 "open-ils.cstore.direct.config.i18n_locale.search.atomic",
350 {"code" => {"!=" => undef}},
351 {"order_by" => {"i18n_l" => "name"}}
353 $session->disconnect();