source: trunk/cic-hcap/perllib/plugins/CICPlug.pm@ 11861

Last change on this file since 11861 was 11861, checked in by mdewsnip, 18 years ago

Changed file to have Unix line endings.

  • Property svn:keywords set to Author Date Id Revision
File size: 48.7 KB
Line 
1###########################################################################
2#
3# CICPlug.pm
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 2005 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package CICPlug;
27
28
29use BasPlug;
30use DBI;
31use strict;
32
33
34sub BEGIN {
35 @CICPlug::ISA = ('BasPlug');
36}
37
38
39my $arguments =
40 [
41 { 'name' => "images_directory",
42 'type' => "string",
43 'deft' => "",
44 'reqd' => "yes" },
45 { 'name' => "cache_directory",
46 'type' => "string",
47 'deft' => &util::filename_cat($ENV{'GSDLHOME'}, "tmp"),
48 'reqd' => "no" },
49 { 'name' => "large_image_options",
50 'type' => "string",
51 'deft' => "",
52 'reqd' => "no" },
53 { 'name' => "large_image_type",
54 'type' => "string",
55 'deft' => "jpg",
56 'reqd' => "no" },
57 { 'name' => "large_image_width",
58 'type' => "string",
59 'deft' => "1250",
60 'reqd' => "no" },
61 { 'name' => "medium_image_options",
62 'type' => "string",
63 'deft' => "",
64 'reqd' => "no" },
65 { 'name' => "medium_image_type",
66 'type' => "string",
67 'deft' => "jpg",
68 'reqd' => "no" },
69 { 'name' => "medium_image_width",
70 'type' => "string",
71 'deft' => "375",
72 'reqd' => "no" },
73 { 'name' => "small_image_options",
74 'type' => "string",
75 'deft' => "",
76 'reqd' => "no" },
77 { 'name' => "small_image_type",
78 'type' => "string",
79 'deft' => "jpg",
80 'reqd' => "no" },
81 { 'name' => "small_image_width",
82 'type' => "string",
83 'deft' => "125",
84 'reqd' => "no" }
85 ];
86
87my $options = { 'name' => "CICPlug",
88 'desc' => "{CICPlug.desc}",
89 'abstract' => "no",
90 'inherits' => "yes" };
91
92
93sub get_default_process_exp
94{
95 return q^(?i)\.mdb$^;
96}
97
98
99sub new
100{
101 my ($class) = shift (@_);
102 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
103 push(@$pluginlist, $class);
104
105 if (defined $arguments) { push(@{$hashArgOptLists->{"ArgList"}}, @{$arguments}); }
106 if (defined $options) { push(@{$hashArgOptLists->{"OptList"}}, $options); }
107
108 my $self = (defined $hashArgOptLists) ? new BasPlug($pluginlist,$inputargs,$hashArgOptLists) : new BasPlug($pluginlist,$inputargs);
109
110 return bless $self, $class;
111}
112
113
114my $state_abbr_to_name_mapping = {
115 "AL" => "Alabama",
116 "AK" => "Alaska",
117 "AZ" => "Arizona",
118 "AR" => "Arkansas",
119 "CA" => "California",
120 "CO" => "Colorado",
121 "CT" => "Connecticut",
122 "DE" => "Delaware",
123 "FL" => "Florida",
124 "GA" => "Georgia",
125 "HI" => "Hawaii",
126 "ID" => "Idaho",
127 "IL" => "Illinois",
128 "IN" => "Indiana",
129 "IA" => "Iowa",
130 "KS" => "Kansas",
131 "KY" => "Kentucky",
132 "LA" => "Louisiana",
133 "ME" => "Maine",
134 "MD" => "Maryland",
135 "MA" => "Massachusetts",
136 "MI" => "Michigan",
137 "MN" => "Minnesota",
138 "MS" => "Mississippi",
139 "MO" => "Missouri",
140 "MT" => "Montana",
141 "NE" => "Nebraska",
142 "NV" => "Nevada",
143 "NH" => "New Hampshire",
144 "NJ" => "New Jersey",
145 "NM" => "New Mexico",
146 "NY" => "New York",
147 "NC" => "North Carolina",
148 "ND" => "North Dakota",
149 "OH" => "Ohio",
150 "OK" => "Oklahoma",
151 "OR" => "Oregon",
152 "PA" => "Pennsylvania",
153 "RI" => "Rhode Island",
154 "SC" => "South Carolina",
155 "SD" => "South Dakota",
156 "TN" => "Tennessee",
157 "TX" => "Texas",
158 "UT" => "Utah",
159 "VT" => "Vermont",
160 "VA" => "Virginia",
161 "WA" => "Washington",
162 "WV" => "West Virginia",
163 "WI" => "Wisconsin",
164 "WY" => "Wyoming"
165 };
166
167
168my $place_type_id_to_name_mapping = {
169 "1" => "Individual building",
170 "2" => "Landscape site",
171 "3" => "Campus arrangement",
172 "4" => "Building group",
173};
174
175
176sub read
177{
178 my $self = shift (@_);
179 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
180
181 $self->{'filename'} = &util::filename_cat($base_dir, $file);
182 if ($self->{'filename'} !~ /$self->{'process_exp'}/ || !-f $self->{'filename'}) {
183 return undef;
184 }
185 $self->{'processor'} = $processor;
186 $self->{'gli'} = $gli;
187
188 # Open connection to Access database
189 my $dbh = DBI->connect('dbi:ODBC:CIC-HCAP');
190
191 $self->process_institutions($dbh);
192 $self->process_places($dbh);
193 $self->process_designers($dbh);
194
195 return 1;
196}
197
198
199sub process_institutions
200{
201 my $self = shift(@_);
202 my $dbh = shift(@_);
203
204 # Prepare SQL statement for getting everything from the Institution table
205 my $institution_sql_statement = "SELECT * FROM tblInstitution"; # WHERE Institution_ID<200";
206 my $institution_sql_handle = $dbh->prepare($institution_sql_statement);
207 $institution_sql_handle->{LongReadLen} = 65536;
208 $institution_sql_handle->execute() or die "Could not execute SQL statement.";
209
210 # Prepare SQL statement for getting the Institution places
211 my $institution_places_sql_statement = "SELECT Entry_ID,Current_name FROM tblPlace WHERE PlaceType>0 AND Institution_ID=?";
212 my $institution_places_sql_handle = $dbh->prepare($institution_places_sql_statement);
213 $institution_places_sql_handle->{LongReadLen} = 65536;
214
215 # Prepare SQL statement for getting the Institution best place image location
216 my $institution_best_place_image_location_sql_statement = "SELECT Location FROM tblImages WHERE FileType=1 AND FileName=?";
217 my $institution_best_place_image_location_sql_handle = $dbh->prepare($institution_best_place_image_location_sql_statement);
218 $institution_best_place_image_location_sql_handle->{LongReadLen} = 65536;
219
220 # Prepare SQL statement for getting the Institution places images
221 my $institution_places_images_sql_statement = "SELECT FileName FROM tblImages,tblPlace WHERE tblImages.FileType=1 AND tblImages.Entry_ID=tblPlace.Entry_ID AND tblPlace.Institution_ID=?";
222 my $institution_places_images_sql_handle = $dbh->prepare($institution_places_images_sql_statement);
223 $institution_places_images_sql_handle->{LongReadLen} = 65536;
224
225 # Prepare SQL statement for getting the Institution campus plans
226 my $institution_campus_plans_sql_statement = "SELECT * FROM tblCampusMaps WHERE Electronic=1 AND Institution_ID=?";
227 my $institution_campus_plans_sql_handle = $dbh->prepare($institution_campus_plans_sql_statement);
228 $institution_campus_plans_sql_handle->{LongReadLen} = 65536;
229
230 # Create a document object for each institution
231 my %institution_state_to_name_mapping;
232 my %institution_name_to_id_mapping;
233 while (my $row_hashref = $institution_sql_handle->fetchrow_hashref) {
234 # Skip any institutions that didn't respond
235 next if !defined($row_hashref->{"City"});
236
237 my $institution_id = $row_hashref->{"Institution_ID"};
238 # print STDERR " Institution $institution_id\n";
239 my $institution_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
240 $institution_doc_obj->set_OID("i$institution_id");
241 &new_metadata_entry($institution_doc_obj, "DocumentType", "Institution");
242
243 # For some reason the hyphen seems to be lost from the Zip field, so add it back in
244 my $institution_zip = $row_hashref->{"Zip"};
245 if ($institution_zip =~ /^(\d\d\d\d\d)(\d\d\d\d)$/) {
246 $row_hashref->{"Zip"} = $1 . "-" . $2;
247 }
248
249 # Map state to full name
250 $row_hashref->{"State"} = $state_abbr_to_name_mapping->{$row_hashref->{"State"}};
251
252 # Get the places in this institution
253 my $institution_random_place_id;
254 my $institution_places_list_html = "";
255 $institution_places_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
256 while (my $institution_places_match_hashref = $institution_places_sql_handle->fetchrow_hashref) {
257 my $institution_place_id = $institution_places_match_hashref->{"Entry_ID"};
258 my $institution_place_name = $institution_places_match_hashref->{"Current_name"};
259 $institution_places_list_html .= "<span class=\"cictext\"><a href=\"_gwcgi_?a=d&d=p$institution_place_id\">$institution_place_name</a></span><br />\n";
260 }
261 &new_metadata_entry($institution_doc_obj, "InstitutionPlacesListHTML", $institution_places_list_html);
262
263 # Get the best place image for this institution
264 my $institution_best_place_image_name = $row_hashref->{"Best_image"};
265 if (!defined($institution_best_place_image_name) || $institution_best_place_image_name eq "") {
266 # Some institutions have no electronic images, and thus have no best image
267 $institution_places_images_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
268 if (defined($institution_places_images_sql_handle->fetchrow_hashref())) {
269 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='No best image'>\n" if ($self->{'gli'});
270 print STDERR "Error: Institution $institution_id -- No best image.\n";
271 $self->{'num_not_processed'}++;
272 next;
273 }
274 &new_metadata_entry($institution_doc_obj, "InstitutionBestPlaceImageHTML", "");
275 }
276 else {
277 # Get the file location of the best place image for this institution
278 $institution_best_place_image_location_sql_handle->execute($institution_best_place_image_name) or die "Could not execute SQL statement.";
279 my $institution_best_place_image_location = $institution_best_place_image_location_sql_handle->fetchrow();
280 if (!defined($institution_best_place_image_location) || $institution_best_place_image_location eq "") {
281 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='Could not match best image $institution_best_place_image_name to a file'>\n" if ($self->{'gli'});
282 print STDERR "Error: Institution $institution_id -- Could not match best image $institution_best_place_image_name to a file.\n";
283 $self->{'num_not_processed'}++;
284 next;
285 }
286
287 $self->new_place_image($institution_doc_obj, $institution_best_place_image_location, "medium");
288 $self->new_place_image($institution_doc_obj, $institution_best_place_image_location, "large");
289
290 my $institution_best_place_image_large_file_name = $institution_best_place_image_name . "-large.jpg";
291 $institution_best_place_image_large_file_name =~ s/ /%20/g;
292 my $institution_best_place_image_large_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$institution_best_place_image_large_file_name";
293 my $institution_best_place_image_medium_file_name = $institution_best_place_image_name . "-medium.jpg";
294 $institution_best_place_image_medium_file_name =~ s/ /%20/g;
295 my $institution_best_place_image_medium_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$institution_best_place_image_medium_file_name";
296 &new_metadata_entry($institution_doc_obj, "InstitutionBestPlaceImageHTML", "<a href=\"$institution_best_place_image_large_file_link\"><img src=\"$institution_best_place_image_medium_file_link\"/><br /><span class=\"cictext\">$institution_best_place_image_name</span></a>");
297 }
298
299 # Get institution campus plans
300 my $institution_campus_plans_list_html = "";
301 $institution_campus_plans_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
302 while (my $institution_campus_plans_match_hashref = $institution_campus_plans_sql_handle->fetchrow_hashref) {
303 my $institution_campus_plan_name = $institution_campus_plans_match_hashref->{"NameAndFormat"};
304 my $institution_campus_plan_image_location = $institution_campus_plans_match_hashref->{"Location_electronic"};
305
306 $self->new_place_image($institution_doc_obj, $institution_campus_plan_image_location, "large");
307
308 my $institution_campus_plan_image_large_file_name = $institution_campus_plan_name . "-large.jpg";
309 $institution_campus_plan_image_large_file_name =~ s/ /%20/g;
310 my $institution_campus_plan_image_large_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$institution_campus_plan_image_large_file_name";
311 $institution_campus_plans_list_html .= "<a href=\"$institution_campus_plan_image_large_file_link\"><span class=\"cictext\">$institution_campus_plan_name</span></a><br />";
312 }
313 &new_metadata_entry($institution_doc_obj, "InstitutionCampusPlansListHTML", $institution_campus_plans_list_html);
314
315 # Add each field from the table as metadata
316 foreach my $key (keys(%$row_hashref)) {
317 my $value = $row_hashref->{$key};
318 if (defined($value)) {
319 &new_metadata_entry($institution_doc_obj, $key, $value);
320 }
321 }
322
323 $institution_doc_obj->add_utf8_text($institution_doc_obj->get_top_section(), "Some dummy text.");
324 $self->{'processor'}->process($institution_doc_obj);
325 $self->{'num_processed'}++;
326
327 # Build mappings for creating the static macrofiles
328 my $institution_name = $row_hashref->{"Institution_Name"};
329 $institution_name_to_id_mapping{$institution_name} = $institution_id;
330 my $institution_state = $row_hashref->{"State"};
331 push(@{$institution_state_to_name_mapping{$institution_state}}, $institution_name);
332 }
333
334 # Write the institutions.dm macrofile
335 &write_static_browser_macrofile("institutions", \%institution_name_to_id_mapping, "i");
336
337 # Write the states.dm macrofile
338 &write_state_browser_macrofile("states", \%institution_state_to_name_mapping, \%institution_name_to_id_mapping);
339}
340
341
342sub process_places
343{
344 my $self = shift(@_);
345 my $dbh = shift(@_);
346
347 # Prepare SQL statement for getting everything from the Place table
348 my $place_sql_statement = "SELECT * FROM tblPlace";
349 my $place_sql_handle = $dbh->prepare($place_sql_statement);
350 $place_sql_handle->{LongReadLen} = 65536;
351 $place_sql_handle->execute() or die "Could not execute SQL statement.";
352
353 # Prepare SQL statement for getting the Place institution
354 my $place_institution_sql_statement = "SELECT Institution_Name FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID and tblPlace.Entry_ID=?";
355 my $place_institution_sql_handle = $dbh->prepare($place_institution_sql_statement);
356
357 # Prepare SQL statement for getting the Place "date of construction"
358 my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
359 my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
360
361 # Prepare SQL statement for getting the Place images
362 my $place_images_sql_statement = "SELECT FileName,Location FROM tblImages WHERE FileType=1 AND Entry_ID=?";
363 my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
364 $place_images_sql_handle->{LongReadLen} = 65536;
365
366 # Prepare SQL statement for getting the Place materials
367 my $place_materials_sql_statement = "SELECT * FROM tblDescription_building WHERE Entry_ID=?";
368 my $place_materials_sql_handle = $dbh->prepare($place_materials_sql_statement);
369 $place_materials_sql_handle->{LongReadLen} = 65536;
370
371 # Prepare SQL statement for getting the Place building styles
372 my $place_styles_sql_statement = "SELECT Architectural_Classification FROM tblArchTypes,jnxtblArchPlace WHERE tblArchTypes.ArchType_ID=jnxtblArchPlace.ArchType_ID AND Entry_ID=?";
373 my $place_styles_sql_handle = $dbh->prepare($place_styles_sql_statement);
374 $place_styles_sql_handle->{LongReadLen} = 65536;
375
376 # Prepare SQL statement for getting the Place functions
377 my $place_functions_sql_statement = "SELECT Function,Year,Prefix FROM tblFunction_and_dates WHERE Entry_ID=?";
378 my $place_functions_sql_handle = $dbh->prepare($place_functions_sql_statement);
379 $place_functions_sql_handle->{LongReadLen} = 65536;
380
381 # Prepare SQL statement for getting the Place significance
382 my $place_significance_sql_statement = "SELECT SigType FROM tblSigTypes,SigPlace WHERE tblSigTypes.SigTypes_ID=SigPlace.SigType_ID+1 AND SigPlace.Entry_ID=?";
383 my $place_significance_sql_handle = $dbh->prepare($place_significance_sql_statement);
384 $place_significance_sql_handle->{LongReadLen} = 65536;
385
386 # Prepare SQL statement for getting the Place references
387 my $place_references_sql_statement = "SELECT Bibliography FROM tblReferences WHERE Entry_ID=?";
388 my $place_references_sql_handle = $dbh->prepare($place_references_sql_statement);
389 $place_references_sql_handle->{LongReadLen} = 65536;
390
391 # Prepare SQL statement for getting the Place narrative
392 my $place_narrative_sql_statement = "SELECT Narrative FROM tblSignificance_Narrative WHERE Entry_ID=?";
393 my $place_narrative_sql_handle = $dbh->prepare($place_narrative_sql_statement);
394 $place_narrative_sql_handle->{LongReadLen} = 65536;
395
396 # Prepare SQL statement for getting the Place state
397 my $place_state_sql_statement = "SELECT State FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID AND Entry_ID=?";
398 my $place_state_sql_handle = $dbh->prepare($place_state_sql_statement);
399 $place_state_sql_handle->{LongReadLen} = 65536;
400
401 # Create a document object for each place
402 my %place_type_to_names_mapping;
403 my %place_style_to_names_mapping;
404 my %place_date_to_names_mapping;
405 my %place_function_to_names_mapping;
406 my %place_name_to_id_mapping;
407 my %place_id_to_institution_name_mapping;
408 while (my $row_hashref = $place_sql_handle->fetchrow_hashref) {
409 my $place_id = $row_hashref->{"Entry_ID"};
410 # print STDERR " Place $place_id\n";
411 my $place_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
412 $place_doc_obj->set_OID("p$place_id");
413 &new_metadata_entry($place_doc_obj, "DocumentType", "Place");
414
415 # Convert the place type ID into a name
416 $row_hashref->{"PlaceType"} = $place_type_id_to_name_mapping->{$row_hashref->{"PlaceType"}};
417
418 # Add each field from the table as metadata
419 foreach my $key (keys(%$row_hashref)) {
420 my $value = $row_hashref->{$key};
421 if (defined($value)) {
422 &new_metadata_entry($place_doc_obj, $key, $value);
423 }
424 }
425
426 # Get place name
427 my $place_name = $row_hashref->{"Current_name"};
428 if (!defined($place_name)) {
429 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing place name'>\n" if ($self->{'gli'});
430 print STDERR "Error: Place $place_id -- Missing place name.\n";
431 $self->{'num_not_processed'}++;
432 next;
433 }
434
435 # Get place type
436 my $place_type = $row_hashref->{"PlaceType"};
437 if (!defined($place_type)) {
438 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing place type'>\n" if ($self->{'gli'});
439 print STDERR "Error: Place $place_id -- Missing place type.\n";
440 $self->{'num_not_processed'}++;
441 next;
442 }
443
444 # Get place date of construction, except for landscape sites which have no date
445 $place_construction_date_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
446 my $place_construction_date_value = $place_construction_date_sql_handle->fetchrow();
447 if (!defined($place_construction_date_value) && $place_type eq "Landscape site") {
448 # Landscape sites may not have a construction date
449 $place_construction_date_value = "";
450 }
451 if (!defined($place_construction_date_value)) {
452 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing construction date'>\n" if ($self->{'gli'});
453 print STDERR "Error: Place $place_id -- Missing construction date.\n";
454 $self->{'num_not_processed'}++;
455 next;
456 }
457 &new_metadata_entry($place_doc_obj, "Construction_date", $place_construction_date_value);
458
459 # Create place styles mapping
460 $place_styles_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
461 while (my $place_styles_match_hashref = $place_styles_sql_handle->fetchrow_hashref()) {
462 my $place_style = $place_styles_match_hashref->{"Architectural_Classification"};
463 push(@{$place_style_to_names_mapping{$place_style}}, $place_name);
464 &new_metadata_entry($place_doc_obj, "Style", $place_style);
465 }
466
467 # Get place institution
468 $place_institution_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
469 my $place_institution = $place_institution_sql_handle->fetchrow();
470 &new_metadata_entry($place_doc_obj, "Institution_name", $place_institution);
471 $place_id_to_institution_name_mapping{$place_id} = ", " . $place_institution;
472
473 # Get place state (for searching)
474 $place_state_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
475 my $place_state_abbr = $place_state_sql_handle->fetchrow();
476 &new_metadata_entry($place_doc_obj, "State", $place_state_abbr . " " . $state_abbr_to_name_mapping->{$place_state_abbr});
477
478 # Create place dates mapping
479 my $place_time_period = $place_construction_date_value;
480 if ($place_construction_date_value =~ /^(\d\d\d\d).*$/) {
481 $place_construction_date_value =~ s/^(\d\d\d\d).*$/$1/;
482 if ($place_construction_date_value < 1800) { $place_time_period = "pre-1800"; }
483 elsif ($place_construction_date_value < 1850) { $place_time_period = "1800-1850"; }
484 elsif ($place_construction_date_value < 1900) { $place_time_period = "1850-1900"; }
485 elsif ($place_construction_date_value < 1945) { $place_time_period = "1900-1945"; }
486 elsif ($place_construction_date_value < 1995) { $place_time_period = "1945-1995"; }
487 else { $place_time_period = "post-1995"; }
488 push(@{$place_date_to_names_mapping{$place_time_period}}, $place_name);
489 }
490 &new_metadata_entry($place_doc_obj, "Time_period", $place_time_period);
491
492 # Get place materials (individual buildings only)
493 if ($row_hashref->{"PlaceType"} eq "Individual building") {
494 $place_materials_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
495 my $place_materials_match_hashref = $place_materials_sql_handle->fetchrow_hashref();
496 &new_metadata_entry($place_doc_obj, "MaterialFoundation", $place_materials_match_hashref->{"foundation"} || "");
497 &new_metadata_entry($place_doc_obj, "MaterialRoof", $place_materials_match_hashref->{"roof"} || "");
498 &new_metadata_entry($place_doc_obj, "MaterialWalls", $place_materials_match_hashref->{"walls"} || "");
499 }
500
501 # Get place functions
502 my $place_functions = "";
503 my $place_functions_table_html = "";
504 $place_functions_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
505 while (my $place_functions_match_hashref = $place_functions_sql_handle->fetchrow_hashref()) {
506 my $place_function = $place_functions_match_hashref->{"Function"};
507 if (!defined($place_function)) {
508 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing function'>\n" if ($self->{'gli'});
509 print STDERR "Error: Place $place_id -- Missing function.\n";
510 next;
511 }
512 my $place_year = $place_functions_match_hashref->{"Year"};
513 if (!defined($place_year)) {
514 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing function year'>\n" if ($self->{'gli'});
515 print STDERR "Error: Place $place_id -- Missing function year.\n";
516 next;
517 }
518 my $place_year_prefix = $place_functions_match_hashref->{"Prefix"} || "";
519 $place_functions .= "$place_function ";
520 $place_functions_table_html .= "<tr><td valign=\"top\"><nobr>$place_year_prefix $place_year</nobr>&nbsp;</td><td valign=\"top\">$place_function</td></tr>";
521
522 # Create place functions mapping
523 $place_function =~ s/\(.*?\)//g;
524 $place_function =~ s/^\s*//;
525 $place_function =~ s/\s*$//;
526 next if ($place_function eq "");
527 push(@{$place_function_to_names_mapping{$place_function}}, $place_name);
528 }
529 &new_metadata_entry($place_doc_obj, "Functions", $place_functions);
530 &new_metadata_entry($place_doc_obj, "PlaceFunctionsTableHTML", "<table cellpadding=\"0\" cellspacing=\"0\">" . $place_functions_table_html . "</table>");
531
532 # Get place significance
533 $place_significance_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
534 while (my $place_significance_match_hashref = $place_significance_sql_handle->fetchrow_hashref()) {
535 my $place_significance = $place_significance_match_hashref->{"SigType"};
536 &new_metadata_entry($place_doc_obj, "Significance", lc($place_significance));
537 }
538
539 # Get place references
540 $place_references_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
541 my $place_references = $place_references_sql_handle->fetchrow();
542 if (defined($place_references)) {
543 &new_metadata_entry($place_doc_obj, "References", &rtf_to_html($place_references));
544 }
545
546 # Get place narrative
547 $place_narrative_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
548 my $place_narrative = $place_narrative_sql_handle->fetchrow();
549 if (defined($place_narrative)) {
550 $place_narrative = &rtf_to_html($place_narrative);
551 $place_narrative =~ s/<br \/>(\s|\n)*$//; # Remove any trailing <br /> tags
552 &new_metadata_entry($place_doc_obj, "Narrative", $place_narrative);
553 }
554
555 # Get place images
556 my $place_images_html = "";
557 $place_images_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
558 while (my $place_images_match_hashref = $place_images_sql_handle->fetchrow_hashref) {
559 my $place_image_location = $place_images_match_hashref->{"Location"};
560 $self->new_place_image($place_doc_obj, $place_image_location, "small");
561 $self->new_place_image($place_doc_obj, $place_image_location, "large");
562
563 my $place_image_name = $place_images_match_hashref->{"FileName"};
564 my $place_image_large_file_name = $place_image_name . "-large.jpg";
565 $place_image_large_file_name =~ s/ /%20/g;
566 my $place_image_large_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$place_image_large_file_name";
567 my $place_image_small_file_name = $place_image_name . "-small.jpg";
568 $place_image_small_file_name =~ s/ /%20/g;
569 my $place_image_small_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$place_image_small_file_name";
570 $place_images_html .= "<tr><td valign=\"top\"><a href=\"$place_image_large_file_link\"><img src=\"$place_image_small_file_link\"/></a></td><td valign=\"top\"><a href=\"$place_image_large_file_link\"><span class=\"cictext\">$place_image_name</span></a></td></tr>\n";
571 }
572
573 &new_metadata_entry($place_doc_obj, "PlaceImagesHTML", "<table>" . $place_images_html . "</table>");
574
575 $place_doc_obj->add_utf8_text($place_doc_obj->get_top_section(), "Some dummy text.");
576 $self->{'processor'}->process($place_doc_obj);
577 $self->{'num_processed'}++;
578
579 # Build mappings for creating the static macrofiles
580 $place_name_to_id_mapping{$place_name} = $place_id;
581 push(@{$place_type_to_names_mapping{$place_type}}, $place_name);
582 }
583
584 &write_bilevel_static_browser_macrofile("types", \%place_type_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping, "p", 2);
585 &write_bilevel_static_browser_macrofile("styles", \%place_style_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping, "p", 2);
586 &write_bilevel_static_browser_macrofile("dates", \%place_date_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping, "p", 2);
587 &write_bilevel_static_browser_macrofile("functions", \%place_function_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping, "p", 2);
588}
589
590
591sub process_designers
592{
593 my $self = shift(@_);
594 my $dbh = shift(@_);
595
596 # Prepare SQL statement for getting all the Architects from the Place table
597 my $designer_sql_statement = "SELECT Architect_Name,Entry_ID FROM tblConstruction_and_dates";
598 my $designer_sql_handle = $dbh->prepare($designer_sql_statement);
599 $designer_sql_handle->{LongReadLen} = 65536;
600 $designer_sql_handle->execute() or die "Could not execute SQL statement.";
601
602 # Prepare SQL statement for getting the Place images
603 my $place_images_sql_statement = "SELECT FileName,Location FROM tblImages WHERE FileType=1 AND Entry_ID=?";
604 my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
605 $place_images_sql_handle->{LongReadLen} = 65536;
606
607 # Get a list of all the designers, and the places they worked on
608 my %designer_name_to_place_ids_mapping;
609 my %designer_name_to_id_mapping;
610 my $designer_count = 0;
611 while (my $designer_hashref = $designer_sql_handle->fetchrow_hashref) {
612 my $designer_names_string = $designer_hashref->{"Architect_Name"};
613 next if !defined($designer_names_string);
614 foreach my $designer_name (split(/;/, $designer_names_string)) {
615 $designer_name =~ s/\(.*?\)//g;
616 $designer_name =~ s/^\s*//;
617 $designer_name =~ s/\s*$//;
618
619 if (!defined($designer_name_to_id_mapping{$designer_name})) {
620 $designer_count++;
621 $designer_name_to_id_mapping{$designer_name} = "$designer_count";
622 }
623
624 push(@{$designer_name_to_place_ids_mapping{$designer_name}}, $designer_hashref->{"Entry_ID"});
625 }
626 }
627
628 # Create a document object for each designer
629 foreach my $designer_name (keys %designer_name_to_place_ids_mapping) {
630 my $designer_id = $designer_name_to_id_mapping{$designer_name};
631 # print STDERR " Designer $designer_id\n";
632 my $designer_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
633 $designer_doc_obj->set_OID("d$designer_id");
634 &new_metadata_entry($designer_doc_obj, "DocumentType", "Designer");
635
636 &new_metadata_entry($designer_doc_obj, "Designer_name", $designer_name);
637
638 my $designer_places_image_html = "";
639 foreach my $designer_place_id (@{$designer_name_to_place_ids_mapping{$designer_name}}) {
640 # Get the first image for this place
641 $place_images_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
642 my $designer_place_image_match_hashref = $place_images_sql_handle->fetchrow_hashref();
643 if (defined($designer_place_image_match_hashref)) {
644 my $designer_place_image_location = $designer_place_image_match_hashref->{"Location"};
645 $self->new_place_image($designer_doc_obj, $designer_place_image_location, "small");
646
647 my $designer_place_image_name = $designer_place_image_match_hashref->{"FileName"};
648 my $designer_place_image_small_file_name = $designer_place_image_name . "-small.jpg";
649 $designer_place_image_small_file_name =~ s/ /%20/g;
650 my $designer_place_image_small_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$designer_place_image_small_file_name";
651 $designer_places_image_html .= "<tr><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\"><img src=\"$designer_place_image_small_file_link\"/></a></td><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\"><span class=\"cictext\">$designer_place_image_name</span></a></td></tr>\n";
652 }
653 }
654
655 &new_metadata_entry($designer_doc_obj, "DesignerPlacesImageHTML", "<table>" . $designer_places_image_html . "</table>");
656
657 $designer_doc_obj->add_utf8_text($designer_doc_obj->get_top_section(), "Some dummy text.");
658 $self->{'processor'}->process($designer_doc_obj);
659 $self->{'num_processed'}++;
660 }
661
662 # Write the designers.dm macrofile
663 &write_static_browser_macrofile("designers", \%designer_name_to_id_mapping, "d", 2);
664}
665
666
667sub new_metadata_entry
668{
669 my ($doc_obj, $metadata_name, $metadata_value) = (@_);
670
671 # Don't bother with empty metadata
672 return if ($metadata_value eq "");
673
674 # Spaces aren't allowed in metadata names
675 $metadata_name =~ s/ /_/g;
676
677 # Fix up non-ASCII values
678 $metadata_value =~ s/’/'/g; # ' # (for Emacs)
679 $metadata_value =~ s/“/"/g;
680 $metadata_value =~ s/”/"/g;
681 $metadata_value =~ s/–/-/g;
682 $metadata_value =~ s/\347/c/g; # !! TO DO
683 $metadata_value =~ s/\351/e/g; # !! TO DO
684
685 # Remove '#' characters around links
686 if ($metadata_value =~ /\#(.*?)\#/) {
687 $metadata_value = $1;
688 }
689
690 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), $metadata_name, $metadata_value);
691}
692
693
694sub rtf_to_html
695{
696 my $rtf_string = shift(@_);
697 $rtf_string =~ s/\{(.*?)\}//g;
698 $rtf_string =~ s/\\rquote /'/g; # ' # (for Emacs)
699 $rtf_string =~ s/\\pard//g;
700 $rtf_string =~ s/\\par/<br \/>/g;
701 $rtf_string =~ s/\\i0 /<\/i>/g;
702 $rtf_string =~ s/\\i /<i>/g;
703 $rtf_string =~ s/\\~/ /g;
704 $rtf_string =~ s/\\([A-Za-z0-9]+)//g;
705 $rtf_string =~ s/\}//g;
706
707 # Assume non-ASCII is ISO 8859-1, and convert into HTML entities
708 while ($rtf_string =~ /\\'([a-z0-9][a-z0-9])/) {
709 my $dec = hex($1);
710 $rtf_string =~ s/\\'$1/&#$dec\;/;
711 }
712
713 return $rtf_string;
714}
715
716
717sub new_place_image
718{
719 my $self = shift(@_);
720 my ($doc_obj, $place_image_location, $place_image_size) = (@_);
721
722 # Don't bother with empty values
723 return if ($place_image_location eq "");
724
725 # Convert the server location of the file into the local location of the file
726 my $place_image_file_path = $place_image_location;
727 $place_image_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
728
729 # Create a new section for each image of the place
730 my $place_image_section = $doc_obj->insert_section($doc_obj->get_end_child($doc_obj->get_top_section()));
731 $doc_obj->add_utf8_text($place_image_section, "Some dummy text.");
732 $doc_obj->add_utf8_metadata($place_image_section, "Title", "1");
733
734 if (!-f $place_image_file_path) {
735 print STDERR "<ProcessingError n='$place_image_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
736 print STDERR "Error: Image $place_image_file_path does not exist.\n";
737 return;
738 }
739
740 my $place_image_file_name = $place_image_file_path;
741 $place_image_file_name =~ s/^.*?([^\\]+)$/$1/;
742 my ($image_file_root) = ($place_image_file_name =~ /^(.+)\./);
743
744 # Scale the original image to make the place image
745 my $image_width = $self->{$place_image_size . '_image_width'};
746 my $image_options = "-scale $image_width " . $self->{$place_image_size . '_image_options'};
747 my $image_file_name = $image_file_root . "-$place_image_size." . $self->{$place_image_size . '_image_type'};
748
749 my $original_image_file_path = $place_image_file_path;
750 my $image_type = $place_image_size;
751
752 my $original_image_file_date = (stat($original_image_file_path))[9];
753 my $image_file_path = &util::filename_cat($self->{'cache_directory'}, $image_file_name);
754 my $image_command = "convert -verbose $image_options \"$original_image_file_path\" \"$image_file_path\"";
755 my $image_height;
756
757 # Check if this image has already been generated by looking for a ".inf" file in the tmp directory
758 $image_file_name =~ /^(.*?)\.[^\.]+$/;
759 my $image_info_file_name = $1 . ".inf";
760 my $image_info_file_path = &util::filename_cat($self->{'cache_directory'}, $image_info_file_name);
761 if (-e $image_info_file_path) {
762 open(IMAGE_INFO_FILE, "<$image_info_file_path");
763 my @image_info = <IMAGE_INFO_FILE>;
764 close(IMAGE_INFO_FILE);
765
766 # Read the original image file date and image command from the file and check they match
767 my $old_original_image_file_date = $image_info[0];
768 $old_original_image_file_date =~ s/\n$//;
769 my $old_image_command = $image_info[1];
770 $old_image_command =~ s/\n$//;
771 if ($old_original_image_file_date eq $original_image_file_date && lc($old_image_command) eq lc($image_command)) {
772 # print STDERR "Already generated $image_file_name...\n";
773 $image_width = $image_info[2];
774 $image_width =~ s/\n$//;
775 $image_height = $image_info[3];
776 $image_height =~ s/\n$//;
777 }
778 }
779
780 # Generate the image if it doesn't already exist
781 if (!defined($image_width) || !defined($image_height)) {
782 print STDERR "Generating place image file: $image_file_name...\n";
783 my $outhandle = $self->{'outhandle'};
784 print $outhandle "$image_command\n" if ($self->{'verbosity'} > 2);
785 my $image_result = `$image_command` || "";
786 print $outhandle "RESULT = $image_result\n" if ($self->{'verbosity'} > 2);
787
788 # Get image dimensions
789 if ($image_command !~ /\-scale / && $image_result =~ m/([0-9]+)x([0-9]+)/) {
790 $image_width = $1;
791 $image_height = $2;
792 }
793 elsif ($image_result =~ m/[0-9]+x[0-9]+=>([0-9]+)x([0-9]+)/) {
794 $image_width = $1;
795 $image_height = $2;
796 }
797 elsif ($image_result =~ m/Image Width: (\d+) Image Length: (\d+)/) {
798 $image_width = $1;
799 $image_height = $2;
800 }
801 elsif ($image_result =~ m/JPEG (\d+)x(\d+)/) {
802 $image_width = $1;
803 $image_height = $2;
804 }
805 else {
806 print STDERR "Error: Could not parse image width and height for $original_image_file_path\n";
807 return;
808 }
809 }
810
811 # Associate the image file
812 $doc_obj->associate_file($image_file_path, $image_file_name, undef, $self->{'section'});
813
814 # Add various bits of metadata for the image
815 my $image_metadata_value = $image_file_name;
816 $image_metadata_value =~ s/ /%20/g;
817 $doc_obj->add_utf8_metadata($self->{'section'}, $image_type . "Image", $image_metadata_value);
818 $doc_obj->add_metadata($self->{'section'}, $image_type . "ImageWidth", $image_width);
819 $doc_obj->add_metadata($self->{'section'}, $image_type . "ImageHeight", $image_height);
820 $doc_obj->add_metadata($self->{'section'}, $image_type . "ImagePath", "_httpcollection_/index/assoc/[parent(Top):assocfilepath]/[${image_type}Image]");
821
822 # Write the image info file so we don't have to regenerate this exact image again in the future
823 open(IMAGE_INFO_FILE, ">$image_info_file_path");
824 print IMAGE_INFO_FILE "$original_image_file_date\n";
825 print IMAGE_INFO_FILE "$image_command\n";
826 print IMAGE_INFO_FILE "$image_width\n";
827 print IMAGE_INFO_FILE "$image_height\n";
828 close(IMAGE_INFO_FILE);
829}
830
831
832sub write_static_browser_macrofile
833{
834 my $static_browser_package_name = shift(@_);
835 my $name_to_id_mapping = shift(@_);
836 my $id_prefix = shift(@_);
837 my $table_columns = 2;
838
839 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
840 print STDERR "Writing $static_browser_macrofile_path...\n";
841 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
842 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
843 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
844
845 my %letter_to_name_mapping;
846 foreach my $name (keys %$name_to_id_mapping) {
847 my ($letter) = ($name =~ /^(.)/);
848 push(@{$letter_to_name_mapping{$letter}}, $name);
849 }
850
851 print BROWSER_MACROFILE "<center><b>";
852 foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
853 if (defined($letter_to_name_mapping{$letter})) {
854 print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
855 }
856 else {
857 print BROWSER_MACROFILE "$letter&nbsp;";
858 }
859 }
860 print BROWSER_MACROFILE "</b></center>\n";
861
862 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
863
864 foreach my $letter (sort(keys %letter_to_name_mapping)) {
865 print BROWSER_MACROFILE "<tr><td width=\"50%\"><br /><a name=\"$letter\"/><span style=\"color: black;\"><b>$letter</b></span></td><td width=\"50%\"></td></tr>\n";
866
867 my @letter_names = sort(@{$letter_to_name_mapping{$letter}});
868 my $half_point = ((scalar(@letter_names) % 2 == 0) ? scalar(@letter_names) / 2 : (scalar(@letter_names) + 1) / 2);
869 for (my $i = 0; $i < $half_point; $i++) {
870 print BROWSER_MACROFILE "<tr>";
871
872 my $name = $letter_names[$i];
873 my $id = $id_prefix . $name_to_id_mapping->{$name};
874 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id\">$name</a></td>";
875
876 $name = $letter_names[$i+$half_point];
877 if (defined($name)) {
878 $id = $id_prefix . $name_to_id_mapping->{$name};
879 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id\">$name</a></td>";
880 }
881 else {
882 print BROWSER_MACROFILE "<td></td>";
883 }
884
885 print BROWSER_MACROFILE "</tr>\n";
886 }
887 }
888
889 print BROWSER_MACROFILE "}\n";
890 close(BROWSER_MACROFILE);
891}
892
893sub write_bilevel_static_browser_macrofile
894{
895 my $static_browser_package_root = shift(@_);
896 my $category_to_names_mapping = shift(@_);
897 my $name_to_id_mapping = shift(@_);
898 my $id_to_extra_mapping = shift(@_);
899 my $id_prefix = shift(@_);
900 my $table_columns = shift(@_);
901
902 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_root.dm";
903 print STDERR "Writing $static_browser_macrofile_path...\n";
904 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
905
906 foreach my $category (keys(%{$category_to_names_mapping})) {
907 # print STDERR "Category: $category\n";
908
909 my $static_browser_package_name = $static_browser_package_root . $category;
910 $static_browser_package_name =~ s/\W//g;
911
912 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
913 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
914
915 print BROWSER_MACROFILE "<center><b>";
916 foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
917 print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
918 }
919 print BROWSER_MACROFILE "</b></center>\n";
920
921 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
922
923 my $last_name = "";
924 my $current_letter = "";
925 my $current_position = 0;
926 foreach my $name (sort(@{$category_to_names_mapping->{$category}})) {
927 # Ignore duplicates
928 next if ($name eq $last_name);
929
930 $name =~ /^(.)/;
931 if ($1 ne $current_letter) {
932 if ($current_position > 0) {
933 while ($current_position > 0) {
934 print BROWSER_MACROFILE "<td></td>";
935 $current_position--;
936 }
937 print BROWSER_MACROFILE "</tr>\n";
938 }
939 if ($table_columns == 2) {
940 print BROWSER_MACROFILE "<tr><td width=\"50%\"><br /><a name=\"$1\"/><span style=\"color: black;\"><b>$1</b></span></td><td width=\"50%\"></td></tr>\n";
941 }
942 else {
943 print BROWSER_MACROFILE "<tr><td width=\"33%\"><br /><a name=\"$1\"/><span style=\"color: black;\"><b>$1</b></span></td><td style=\"padding-left: 3px; padding-right: 3px;\" width=\"34%\"></td><td width=\"33%\"></td></tr>\n";
944 }
945 $current_letter = $1;
946 }
947
948 my $id = $name_to_id_mapping->{$name};
949 my $extra = "";
950 if (defined($id_to_extra_mapping)) {
951 $extra = $id_to_extra_mapping->{$id};
952 }
953
954 if ($current_position == 0) {
955 print BROWSER_MACROFILE "<tr>";
956 }
957 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id_prefix$id\">$name</a>$extra</td>";
958 $current_position++;
959 if ($current_position == $table_columns) {
960 print BROWSER_MACROFILE "</tr>\n";
961 $current_position = 0;
962 }
963
964 $last_name = $name;
965 }
966
967 print BROWSER_MACROFILE "}\n\n";
968 }
969
970 close(BROWSER_MACROFILE);
971}
972
973
974sub write_bilevel_static_browser_macrofile_new
975{
976 my $static_browser_package_root = shift(@_);
977 my $category_to_names_mapping = shift(@_);
978 my $name_to_id_mapping = shift(@_);
979 my $id_to_extra_mapping = shift(@_);
980 my $id_prefix = shift(@_);
981 my $table_columns = shift(@_);
982
983 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_root.dm";
984 print STDERR "Writing $static_browser_macrofile_path...\n";
985 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
986
987 foreach my $category (keys(%{$category_to_names_mapping})) {
988 # print STDERR "Category: $category\n";
989
990 my $static_browser_package_name = $static_browser_package_root . $category;
991 $static_browser_package_name =~ s/\W//g;
992
993 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
994 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
995
996 my %letter_to_name_mapping;
997 foreach my $name (@{$category_to_names_mapping->{$category}}) {
998 my ($letter) = ($name =~ /^(.)/);
999 push(@{$letter_to_name_mapping{$letter}}, $name);
1000 }
1001
1002 print BROWSER_MACROFILE "<center><b>";
1003 foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
1004 if (defined($letter_to_name_mapping{$letter})) {
1005 print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
1006 }
1007 else {
1008 print BROWSER_MACROFILE "$letter&nbsp;";
1009 }
1010 }
1011 print BROWSER_MACROFILE "</b></center>\n";
1012
1013 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
1014
1015 foreach my $letter (sort(keys %letter_to_name_mapping)) {
1016 print BROWSER_MACROFILE "<tr><td width=\"50%\"><br /><a name=\"$letter\"/><span style=\"color: black;\"><b>$letter</b></span></td><td width=\"50%\"></td></tr>\n";
1017
1018 my @letter_names = sort(@{$letter_to_name_mapping{$letter}});
1019 my $half_point = ((scalar(@letter_names) % 2 == 0) ? scalar(@letter_names) / 2 : (scalar(@letter_names) + 1) / 2);
1020 for (my $i = 0; $i < $half_point; $i++) {
1021 print BROWSER_MACROFILE "<tr>";
1022
1023 my $name = $letter_names[$i];
1024 my $id = $name_to_id_mapping->{$name};
1025 my $extra = $id_to_extra_mapping->{$id};
1026 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id_prefix$id\">$name</a>$extra</td>";
1027
1028 $name = $letter_names[$i+$half_point];
1029 if (defined($name)) {
1030 $id = $name_to_id_mapping->{$name};
1031 $extra = $id_to_extra_mapping->{$id};
1032 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id_prefix$id\">$name</a>$extra</td>";
1033 }
1034 else {
1035 print BROWSER_MACROFILE "<td></td>";
1036 }
1037
1038 print BROWSER_MACROFILE "</tr>\n";
1039 }
1040 }
1041
1042# my $last_name = "";
1043# my $current_letter = "";
1044# my $current_position = 0;
1045# foreach my $name (sort(@{$category_to_names_mapping->{$category}})) {
1046# # Ignore duplicates
1047# next if ($name eq $last_name);
1048
1049# $name =~ /^(.)/;
1050# if ($1 ne $current_letter) {
1051# if ($current_position > 0) {
1052# while ($current_position > 0) {
1053# print BROWSER_MACROFILE "<td></td>";
1054# $current_position--;
1055# }
1056# print BROWSER_MACROFILE "</tr>\n";
1057# }
1058# if ($table_columns == 2) {
1059# print BROWSER_MACROFILE "<tr><td width=\"50%\"><br /><a name=\"$1\"/><span style=\"color: black;\"><b>$1</b></span></td><td width=\"50%\"></td></tr>\n";
1060# }
1061# else {
1062# print BROWSER_MACROFILE "<tr><td width=\"33%\"><br /><a name=\"$1\"/><span style=\"color: black;\"><b>$1</b></span></td><td style=\"padding-left: 3px; padding-right: 3px;\" width=\"34%\"></td><td width=\"33%\"></td></tr>\n";
1063# }
1064# $current_letter = $1;
1065# }
1066
1067# my $id = $name_to_id_mapping->{$name};
1068# my $extra = "";
1069# if (defined($id_to_extra_mapping)) {
1070# $extra = $id_to_extra_mapping->{$id};
1071# }
1072
1073# if ($current_position == 0) {
1074# print BROWSER_MACROFILE "<tr>";
1075# }
1076# if (!defined($name) || !defined($id_prefix) || !defined($id) || !defined($extra)) {
1077# print STDERR "Name: $name\n";
1078# print STDERR "ID prefix: $id_prefix\n";
1079# print STDERR "ID: $id\n";
1080# print STDERR "Extra: $extra\n";
1081# }
1082# print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id_prefix$id\">$name</a>$extra</td>";
1083# $current_position++;
1084# if ($current_position == $table_columns) {
1085# print BROWSER_MACROFILE "</tr>\n";
1086# $current_position = 0;
1087# }
1088
1089# $last_name = $name;
1090# }
1091
1092 print BROWSER_MACROFILE "}\n\n";
1093 }
1094
1095 close(BROWSER_MACROFILE);
1096}
1097
1098
1099sub write_state_browser_macrofile
1100{
1101 my $static_browser_package_name = shift(@_);
1102 my $state_to_name_mapping = shift(@_);
1103 my $name_to_id_mapping = shift(@_);
1104
1105 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
1106 print STDERR "Writing $static_browser_macrofile_path...\n";
1107 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
1108 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
1109 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
1110
1111 print BROWSER_MACROFILE "<center><b>";
1112 foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
1113 # if ($letter !~ /[BEJQXYZ]/) {
1114 print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
1115 # }
1116 # else {
1117 # print BROWSER_MACROFILE "<span style=\"color: #999999\">$letter</span>&nbsp;";
1118 # }
1119 }
1120 print BROWSER_MACROFILE "</b></center>\n";
1121
1122 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
1123
1124 my $current_letter = "";
1125 my $current_position = 0;
1126 foreach my $state (sort(keys %$state_to_name_mapping)) {
1127 if ($current_position > 0) {
1128 while ($current_position > 0) {
1129 print BROWSER_MACROFILE "<td></td>";
1130 $current_position--;
1131 }
1132 print BROWSER_MACROFILE "</tr>\n";
1133 }
1134
1135 print BROWSER_MACROFILE "<tr><td width=\"33%\"><br />";
1136 $state =~ /^(.)/;
1137 if ($1 ne $current_letter) {
1138 print BROWSER_MACROFILE "<a name=\"$1\"/>";
1139 $current_letter = $1;
1140 }
1141 print BROWSER_MACROFILE "<span style=\"color: black;\"><b>$state</b></span></td><td style=\"padding-left: 3px; padding-right: 3px;\" width=\"34%\"></td><td width=\"33%\"></td></tr>\n";
1142
1143 foreach my $name (sort(@{$state_to_name_mapping->{$state}})) {
1144 my $id = $name_to_id_mapping->{$name};
1145
1146 if ($current_position == 0) {
1147 print BROWSER_MACROFILE "<tr>";
1148 }
1149 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=i$id\">$name</a></td>";
1150 $current_position++;
1151 if ($current_position == 3) {
1152 print BROWSER_MACROFILE "</tr>\n";
1153 $current_position = 0;
1154 }
1155 }
1156 }
1157
1158 print BROWSER_MACROFILE "}\n";
1159 close(BROWSER_MACROFILE);
1160}
1161
1162
11631;
Note: See TracBrowser for help on using the repository browser.