source: trunk/gsdl/src/recpt/pageaction.cpp@ 7130

Last change on this file since 7130 was 7130, checked in by kjdon, 20 years ago

when generating the homeextra macro need to make sure we get language specific values for collectionname, iconcollection and iconcollectionsmall

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 33.9 KB
Line 
1/**********************************************************************
2 *
3 * pageaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
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
26// Changelog:
27
28// 11th July 2003:
29
30// Added 3 functions to deal with the collection style
31// A deciding function and then 2 functions that actually
32// do the work for us, either images or pulldown.
33
34
35#include "OIDtools.h"
36#include "pageaction.h"
37#include "receptionist.h"
38#include "fileutil.h"
39#include "gsdltools.h"
40#include <time.h>
41
42pageaction::pageaction () {
43
44 status_disabled = true;
45 collector_disabled = true;
46 translator_disabled = true;
47 recpt = NULL;
48
49 // this action uses cgi variables "a", "p", and "hp"
50 cgiarginfo arg_ainfo;
51 arg_ainfo.shortname = "a";
52 arg_ainfo.longname = "action";
53 arg_ainfo.multiplechar = true;
54 arg_ainfo.defaultstatus = cgiarginfo::weak;
55 arg_ainfo.argdefault = "p";
56 arg_ainfo.savedarginfo = cgiarginfo::must;
57 argsinfo.addarginfo (NULL, arg_ainfo);
58
59 arg_ainfo.shortname = "p";
60 arg_ainfo.longname = "page";
61 arg_ainfo.multiplechar = true;
62 arg_ainfo.defaultstatus = cgiarginfo::weak;
63 arg_ainfo.argdefault = "home";
64 arg_ainfo.savedarginfo = cgiarginfo::must;
65 argsinfo.addarginfo (NULL, arg_ainfo);
66
67 arg_ainfo.shortname = "hp";
68 arg_ainfo.longname = "html page";
69 arg_ainfo.multiplechar = true;
70 arg_ainfo.defaultstatus = cgiarginfo::weak;
71 arg_ainfo.argdefault = "";
72 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
73 argsinfo.addarginfo (NULL, arg_ainfo);
74
75 arg_ainfo.shortname = "bp";
76 arg_ainfo.longname = "set preferences button";
77 arg_ainfo.multiplechar = true;
78 arg_ainfo.defaultstatus = cgiarginfo::weak;
79 arg_ainfo.argdefault = "";
80 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
81 argsinfo.addarginfo (NULL, arg_ainfo);
82
83 // the "u" argument will disable the search facility, remove links to the
84 // home and preferences pages, and disable the DocumentButton buttons
85 // (for use when generating static html versions of collections)
86 arg_ainfo.shortname = "u";
87 arg_ainfo.longname = "static page";
88 arg_ainfo.multiplechar = false;
89 arg_ainfo.defaultstatus = cgiarginfo::weak;
90 arg_ainfo.argdefault = "0";
91 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
92 argsinfo.addarginfo (NULL, arg_ainfo);
93}
94
95pageaction::~pageaction () {
96}
97
98bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args,
99 recptprotolistclass * /*protos*/, ostream &/*logout*/) {
100
101 if (args["p"] == "preferences" && !args["bp"].empty()) {
102 if (args["hd"] != "0") args["hd"] = args["hdn"];
103 }
104
105 return true;
106}
107
108void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
109 response_t &response,text_t &response_data,
110 ostream &/*logout*/) {
111 response = content;
112 response_data = "text/html";
113}
114
115// This function helps decide whether we want a
116// images or pulldown style collection display
117// We refer to the macro files for the options
118// for images or pulldown menu and use that to
119// switch to the appropriate function to do the job
120
121// Aly Dharshi
122// 11th July 2003
123
124void pageaction::homepagestyle(displayclass &disp, recptprotolistclass *protos,
125 cgiargsclass &args, ostream &logout)
126{
127
128 const recptconf &configinfo = recpt->get_configinfo();
129
130 if (configinfo.HomePageType == "images") {
131 home_images(disp, protos, args, configinfo, logout);
132
133 } else
134 {
135 home_pulldown(disp, protos, args, configinfo, logout);
136 }
137}
138
139// This function allows for the Greenstone
140// collection to be displayed in a pull down
141// menu similar to that in documentaction.cpp
142
143// Aly Dharshi
144// 11th July 2003
145
146void pageaction::home_pulldown(displayclass &disp, recptprotolistclass *protos,
147 cgiargsclass &args, const recptconf &configinfo,
148 ostream &logout) {
149
150 //text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
151 //bool found_valid_col = false;
152
153 text_t homeextra = "<form method=\"get\" name=\"browse\">\n";
154 homeextra += "<select name=\"collections\" onChange=\"location.href=";
155 homeextra += "document.browse.collections.options[document.browse.collections.selectedIndex].value\">\n";
156
157
158 recptprotolistclass::iterator rprotolist_here = protos->begin();
159 recptprotolistclass::iterator rprotolist_end = protos->end();
160 while (rprotolist_here != rprotolist_end) {
161 if ((*rprotolist_here).p != NULL) {
162
163 text_tarray collist;
164 comerror_t err;
165 (*rprotolist_here).p->get_collection_list (collist, err, logout);
166 if (err == noError) {
167 text_tarray::iterator collist_here = collist.begin();
168 text_tarray::iterator collist_end = collist.end();
169
170 int count = 0;
171 bool first = true;
172 while (collist_here != collist_end) {
173 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
174
175 if (cinfo != NULL) {
176 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
177
178 text_t coll_type = "&ct=";
179 if (cinfo->buildType == "mgpp") {
180 coll_type += "1&qto=";
181
182 // now we also want to check search types to set the qto arg
183 if (cinfo->searchTypes.size() == 0) {
184 coll_type += "3"; // default to 3 (= both)
185 } else {
186 unsigned int search_types = 0;
187 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
188 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
189
190 while (type_here != type_end) {
191 if (*type_here == "form") {
192 search_types |= 2;
193 } else if (*type_here == "plain") {
194 search_types |= 1;
195 }
196 type_here ++;
197 }
198 coll_type += search_types;
199 if (search_types == 3) {
200 // both were specified, now need to look at the order to see which is the default
201 type_here = cinfo->searchTypes.begin();
202 if (*type_here == "form") {
203 coll_type += "&qt=1"; // set the default to form
204 }
205 }
206
207 }
208 }
209 else {
210 coll_type += "0";
211 }
212
213 FilterResponse_t response;
214 text_tset metadata;
215 metadata.insert ("collectionname");
216 text_t lang = args["l"];
217 if (!lang.empty()) {
218 metadata.insert ("collectionname:"+lang);
219 }
220 text_t collectionname = *collist_here;
221
222 if (get_info ("collection", *collist_here, metadata, false,
223 (*rprotolist_here).p, response, logout)) {
224 if (!lang.empty() && !response.docInfo[0].metadata["collectionname:"+lang].values[0].empty()) {
225 collectionname = response.docInfo[0].metadata["collectionname:"+lang].values[0];
226 } else if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
227 collectionname = response.docInfo[0].metadata["collectionname"].values[0];
228 }
229 }
230
231 comerror_t err;
232 text_t optsite = "";
233 text_t site_name = (*rprotolist_here).p->get_site_name (err);
234 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
235
236 text_t link = "_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type;
237 link += "&l=" + args["l"] + "&w=" + args["w"];
238
239 // We are "dynamically" overriding so to speak the
240 // link to the collection aka receptionist.
241
242 if (!cinfo->receptionist.empty())
243 link = cinfo->receptionist;
244
245
246 homeextra += "<option value=\"" + link + "\"";
247 homeextra += ">" + collectionname + "</option>\n";
248
249 }
250
251 collist_here ++;
252 }
253
254 }
255 }
256 rprotolist_here ++;
257 }
258
259 }
260 homeextra += "</select>\n";
261 homeextra += "</form>\n";
262
263 disp.setmacro ("homeextra", "home", homeextra);
264}
265
266// originally called set_homeextra_macro
267// this function displays the Greenstone
268// main page as usual with the graphics for
269// the collections.
270
271// Aly Dharshi
272// 11th July 2003
273
274void pageaction::home_images(displayclass &disp, recptprotolistclass *protos,
275 cgiargsclass &args, const recptconf &configinfo,
276 ostream &logout) {
277
278 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
279 bool found_valid_col = false;
280 recptprotolistclass::iterator rprotolist_here = protos->begin();
281 recptprotolistclass::iterator rprotolist_end = protos->end();
282 while (rprotolist_here != rprotolist_end) {
283 if ((*rprotolist_here).p != NULL) {
284
285 text_tarray collist;
286 comerror_t err;
287 (*rprotolist_here).p->get_collection_list (collist, err, logout);
288 if (err == noError) {
289 text_tarray::iterator collist_here = collist.begin();
290 text_tarray::iterator collist_end = collist.end();
291
292 int count = 0;
293 bool first = true;
294 while (collist_here != collist_end) {
295 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
296
297 if (cinfo != NULL) {
298 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
299
300 text_t coll_type = "&ct=";
301 if (cinfo->buildType == "mgpp") {
302 coll_type += "1&qto=";
303
304 // now we also want to check search types to set the qto arg
305 if (cinfo->searchTypes.size() == 0) {
306 coll_type += "3"; // default to 3 (= both)
307 } else {
308 unsigned int search_types = 0;
309 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
310 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
311
312 while (type_here != type_end) {
313 if (*type_here == "form") {
314 search_types |= 2;
315 } else if (*type_here == "plain") {
316 search_types |= 1;
317 }
318 type_here ++;
319 }
320 coll_type += search_types;
321 if (search_types == 3) {
322 // both were specified, now need to look at the order to see which is the default
323 type_here = cinfo->searchTypes.begin();
324 if (*type_here == "form") {
325 coll_type += "&qt=1"; // set the default to form
326 }
327 }
328
329 }
330 }
331 else {
332 coll_type += "0";
333 }
334
335 found_valid_col = true;
336 FilterResponse_t response;
337 text_tset metadata;
338 metadata.insert ("collectionname");
339 metadata.insert ("iconcollection");
340 metadata.insert ("iconcollectionsmall");
341 // also look for lang specific values
342 text_t lang = args["l"];
343 if (!lang.empty()) {
344 metadata.insert ("collectionname:"+lang);
345 metadata.insert ("iconcollection:"+lang);
346 metadata.insert ("iconcollectionsmall:"+lang);
347 }
348 text_t collectionname = *collist_here;
349 text_t alt = collectionname;
350
351 if (get_info ("collection", *collist_here, metadata, false,
352 (*rprotolist_here).p, response, logout)) {
353 // get the "collectionname"
354 if (!lang.empty() && !response.docInfo[0].metadata["collectionname:"+lang].values[0].empty()) {
355 alt = response.docInfo[0].metadata["collectionname:"+lang].values[0];
356 } else if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
357 alt = response.docInfo[0].metadata["collectionname"].values[0];
358 }
359
360 text_t iconurl;
361 iconurl.clear();
362
363 if (!lang.empty() &&!response.docInfo[0].metadata["iconcollectionsmall:"+lang].values[0].empty()) {
364 iconurl = response.docInfo[0].metadata["iconcollectionsmall:"+lang].values[0];
365 } else if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) {
366 iconurl = response.docInfo[0].metadata["iconcollectionsmall"].values[0];
367 } else if (!lang.empty() && !response.docInfo[0].metadata["iconcollection:"+lang].values[0].empty()) {
368 iconurl = response.docInfo[0].metadata["iconcollection:"+lang].values[0];
369 } else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) {
370 iconurl = response.docInfo[0].metadata["iconcollection"].values[0];
371 }
372
373 if (!iconurl.empty())
374 {
375 // check to see URL is local to colserver
376 text_t::iterator iconurl_head = iconurl.begin();
377 text_t iconhead = substr(iconurl_head,iconurl_head+16);
378 if (iconhead=="_httpcollection_")
379 {
380 // local and using _httpcollection_
381 text_t icontail = substr(iconurl_head+16,iconurl.end());
382 iconurl = "http://" + cinfo->httpdomain
383 + cinfo->httpprefix + "/collect/"
384 + *collist_here + "/" + icontail;
385 }
386 else if (iconurl[0]=='/')
387 {
388 // local but with full path
389 iconurl = "http://" + cinfo->httpdomain + iconurl;
390 }
391
392 collectionname
393 = "<img width=150 border=1 src=\"" + iconurl + "\" alt=\"" + alt + "\">";
394 }
395 else
396 {
397 collectionname = alt;
398 }
399
400 }
401 if ((count%configinfo.HomePageCols == 0) && (!first))
402 homeextra += "</tr><tr valign=top>\n";
403
404 comerror_t err;
405 text_t optsite = "";
406 text_t site_name = (*rprotolist_here).p->get_site_name (err);
407 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
408
409 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type;
410 link += "&l=" + args["l"] + "&w=" + args["w"] + "\">";
411
412 if (!cinfo->receptionist.empty())
413 link = "<a href=\"" + cinfo->receptionist + "\">";
414
415 homeextra += "<td>" + link + collectionname + "</a></td>\n";
416
417 count ++;
418 first = false;
419 }
420 }
421 collist_here ++;
422 }
423
424 for (; count%configinfo.HomePageCols != 0; count ++) homeextra += "<td></td>\n";
425 }
426 }
427 homeextra += "</td></tr>\n<tr>\n";
428 rprotolist_here ++;
429 }
430
431 if (!found_valid_col) {
432 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
433 }
434 homeextra += "</tr></table></center>\n";
435 disp.setmacro ("homeextra", "home", homeextra);
436}
437
438void pageaction::set_collectionlist_macro (displayclass &disp, recptprotolistclass *protos,
439 ostream &logout) {
440
441 text_t collectionlist;
442 int count = 0;
443
444 recptprotolistclass::iterator rprotolist_here = protos->begin();
445 recptprotolistclass::iterator rprotolist_end = protos->end();
446 while (rprotolist_here != rprotolist_end) {
447 if ((*rprotolist_here).p != NULL) {
448
449 text_tarray collist;
450 comerror_t err;
451 (*rprotolist_here).p->get_collection_list (collist, err, logout);
452 if (err == noError) {
453 text_tarray::iterator collist_here = collist.begin();
454 text_tarray::iterator collist_end = collist.end();
455
456 while (collist_here != collist_end) {
457 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
458
459 if (cinfo != NULL) {
460 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
461
462 count ++;
463
464 text_t coll_type = "&ct=";
465 if (cinfo->buildType == "mgpp") {
466 coll_type += "1&qto=";
467
468 // now we also want to check search types to set the qto arg
469 if (cinfo->searchTypes.size() == 0) {
470 coll_type += "3"; // default to 2 (= both)
471 } else {
472 int search_types = 0;
473 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
474 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
475
476 while (type_here != type_end) {
477 if (*type_here == "form") {
478 search_types |= 0x10;
479 } else if (*type_here == "plain") {
480 search_types |= 0x01;
481 }
482 type_here ++;
483 }
484 coll_type += search_types;
485
486 if (search_types == 3) {
487 // both were specified, now need to look at the order to see which is the default
488 type_here = cinfo->searchTypes.begin();
489 if (*type_here == "form") {
490 coll_type += "&qt=1"; // set the default to form
491 }
492 }
493 }
494 }
495 else {
496 coll_type += "0";
497 }
498 FilterResponse_t response;
499 text_tset metadata;
500 metadata.insert ("collectionname");
501 text_t collectionname = *collist_here;
502
503 if (get_info ("collection", *collist_here, metadata, false,
504 (*rprotolist_here).p, response, logout)) {
505 if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
506 collectionname = response.docInfo[0].metadata["collectionname"].values[0];
507 }
508 }
509
510 comerror_t err;
511 text_t optsite = "";
512 text_t site_name = (*rprotolist_here).p->get_site_name (err);
513 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
514
515 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type+"\">";
516
517 if (!cinfo->receptionist.empty())
518 link = "<a href=\"" + cinfo->receptionist + "\">";
519
520 collectionlist += "<li>" + link + collectionname + "</a>\n";
521 }
522 }
523 collist_here ++;
524 }
525 }
526 }
527 rprotolist_here ++;
528 }
529
530 if (count == 1) {
531 collectionlist = "<p>_text1coll_\n<ul>" +
532 collectionlist + "</ul>\n";
533 } else if (count > 1) {
534 collectionlist = "<p>_textmorecolls_(" + text_t(count) +
535 ")\n<ul>" + collectionlist + "</ul>\n";
536 }
537
538 disp.setmacro ("collectionlist", "homehelp", collectionlist);
539}
540
541void pageaction::set_documentation_macro (displayclass &disp) {
542
543 text_t documentation;
544 text_t docsdir = filename_cat(gsdlhome, "docs");
545
546 if (file_exists(filename_cat(docsdir, "User.pdf"))) {
547 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/User.pdf\">_iconpdf_"
548 "</a></td><td>_textuserguide_</td></tr>";
549 }
550
551 if (file_exists(filename_cat(docsdir, "Install.pdf"))) {
552 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Install.pdf\">_iconpdf_"
553 "</a></td><td>_textinstallerguide_</td></tr>";
554 }
555
556 if (file_exists(filename_cat(docsdir, "Develop.pdf"))) {
557 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Develop.pdf\">_iconpdf_"
558 "</a></td><td>_textdeveloperguide_</td></tr>";
559 }
560
561 if (file_exists(filename_cat(docsdir, "Paper.pdf"))) {
562 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Paper.pdf\">_iconpdf_"
563 "</a></td><td>_textpaperguide_</td></tr>";
564 }
565
566 if (!documentation.empty()) {
567 disp.setmacro("documentation", "docs", "<p>\n<table border=0>\n" + documentation + "\n</table>\n");
568 }
569}
570
571void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
572 const text_t &packagename, const text_t &filename) {
573
574 text_t filecontent;
575 char *filenamec = filename.getcstr();
576 ifstream file_in (filenamec);
577 delete filenamec;
578 if (file_in) {
579 char c;
580 file_in.get(c);
581 while (!file_in.eof ()) {
582 if (c == '\n') filecontent += "<br>";
583 filecontent.push_back(c);
584 file_in.get(c);
585 }
586 file_in.close();
587 }
588 disp.setmacro (macroname, packagename, dm_safe(filecontent));
589}
590
591void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
592 recptprotolistclass *protos, ColInfoResponse_t *cinfo,
593 ostream &logout) {
594 // _languageoption_
595 // Create the "interface language" selection box for the preferences
596 // pages. You can use something like "format PreferenceLanguages
597 // en|fr|zn" from within a collect.cfg file to use only a subset of
598 // the available languages for any given collection (for
599 // collection-specific preferences pages). This facility is kind of
600 // ugly though and should be replaced by something better when the
601 // configuration files are tidied up (as should all the other
602 // "format Preference..." options).
603 text_t &arg_l = args["l"];
604 const recptconf &configinfo = recpt->get_configinfo();
605 // put languages in another map to sort them by longname
606 text_tmap languages;
607 languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
608 languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
609 while (thislang != endlang) {
610 languages[(*thislang).second.longname] = (*thislang).first;
611 thislang++;
612 }
613 text_tmap::iterator tlang = languages.begin();
614 text_tmap::iterator elang = languages.end();
615
616 text_t languageoption;
617 bool collection_specific = false;
618
619 if (cinfo != NULL) {
620 text_tmap::const_iterator it = cinfo->format.find ("PreferenceLanguages");
621 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
622 collection_specific = true;
623 text_tset pref_langs;
624 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
625 if (pref_langs.size() > 1) {
626 while (tlang != elang) {
627 if (pref_langs.find((*tlang).second) != pref_langs.end()) {
628 languageoption += "<option value=\"" + (*tlang).second + "\"";
629 if ((*tlang).second == arg_l) languageoption += " selected";
630 languageoption += ">" + (*tlang).first + "\n";
631 }
632 tlang ++;
633 }
634 }
635 }
636 }
637
638 if (!collection_specific) {
639 while (tlang != elang) {
640 languageoption += "<option value=\"" + (*tlang).second + "\"";
641 if ((*tlang).second == arg_l) languageoption += " selected";
642 languageoption += ">" + (*tlang).first + "\n";
643 tlang ++;
644 }
645 }
646
647 if (!languageoption.empty()) {
648 languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
649 languageoption += "</select>\n";
650 disp.setmacro ("languageoption", args["p"], languageoption);
651 }
652
653 // _encodingoption_
654 // create the "encoding" selection box for the preferences page
655 if (configinfo.encodings.size() > 1) {
656 text_t &arg_w = args["w"];
657 text_t encodingoption;
658 text_tmap::const_iterator thisenc = configinfo.encodings.begin();
659 text_tmap::const_iterator endenc = configinfo.encodings.end();
660 while (thisenc != endenc) {
661 encodingoption += "<option value=\"" + (*thisenc).second + "\"";
662 if ((*thisenc).second == arg_w) encodingoption += " selected";
663 encodingoption += ">" + (*thisenc).first + "\n";
664 thisenc ++;
665 }
666
667 encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
668 encodingoption += "</select>\n";
669 disp.setmacro ("encodingoption", args["p"], encodingoption);
670 }
671}
672
673void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
674 recptprotolistclass *protos, ostream &logout) {
675
676 // define_internal_macros sets the following macros:
677
678 // _numdocs_ the number of documents in the collection
679
680 // _builddate_ the date last built
681
682 // if page is "home"
683 // _homeextra_ this is the list of available collections and collection info
684 // to be displayed on the home page
685
686
687 // if page is "preferences"
688 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
689
690 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
691
692 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
693
694
695 // if page is "preferences" or "homepref"
696 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
697
698 // _encodingoption_ encodings to select from
699
700
701 // if page is "about"
702 // _textsubcollections_ the text on which subcollections make up the collection (if
703 // cross-collection searching is being used
704
705 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
706
707 // _numbrowseoptions_ the number of browsing options
708
709 // _prefschanged_ will be set to _textprefschanged_ if the "set preferences" button
710 // was pressed
711
712 // _aboutqueryform_ will be set to "" if the collection isn't searchable
713
714 // if page is "help"
715 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
716
717 // _numbrowseoptions_ the number of browsing options
718
719 // _topicreadingdocs_ this section of the help text differs depending on what type of
720 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
721 // _texthelpreadingdocs_
722
723 // if page is "home" or "homehelp"
724 // _textgocollector_ set to "" if collector is disabled in main.cfg
725 // _textgoadmin_ set to "" if status is disabled in main.cfg
726 // _textgotranslator_ set to "" if translator is disabled in main.cfg
727
728
729 // if page is "homehelp"
730 // _collectionlist_ list of available collections to be displayed on the homehelp page
731
732
733 // if page is "docs"
734 // _documentation_ links to PDF documents if they're available
735
736
737 // if page is "bsummary"
738 // _importlog_ set to contents of collections import.log file
739 // _faillog_ set to contents of collections fail.log file
740
741
742 if (recpt == NULL) {
743 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
744 << " information about any receptionists. The method set_receptionist was\n"
745 << " probably not called from the module which instantiated this action.\n";
746 return;
747 }
748
749 text_t &arg_p = args["p"];
750 text_t &arg_c = args["c"];
751 ColInfoResponse_t *cinfo = NULL;
752
753 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
754 if (collectproto != NULL) {
755 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
756
757 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
758 unsigned long current_time = time(NULL);
759 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
760 disp.setmacro ("builddate", "Global", builddate);
761
762 text_t numbytes;
763 if ((cinfo->numBytes/(1024*1024)) > 1) {
764 numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
765 } else if ((cinfo->numBytes/1024) > 1) {
766 numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
767 } else {
768 numbytes = (text_t)cinfo->numBytes + " bytes";
769 }
770 disp.setmacro("numbytes", "Global", numbytes);
771 }
772
773 //setting _queryformcontent_ so that the query interface is consistent.
774 //also adding usability button if necessary
775 if (arg_p == "about") {
776 if (cinfo == NULL) {
777 disp.setmacro("cvariable", "Global", arg_c);
778 disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
779 return;
780 }
781 else {
782
783 text_tmap::iterator check = cinfo->format.find("QueryInterface");
784 if(check != cinfo->format.end()){
785 if((*check).second=="DateSearch"){
786 text_t current = "_datesearch_";
787 disp.setmacro("optdatesearch","query",current);
788 }
789 }
790 check = cinfo->format.find("Usability");
791 if(check != cinfo->format.end()){
792 disp.setmacro("usability","Global","_imageusab_");
793 disp.setmacro("usabinterface","Global",("_usab"+(*check).second+"_"));
794 disp.setmacro("usabilityscript", "Global", "_usabshowscript_");
795 }
796 }
797 }
798
799 if (arg_p == "home" || arg_p == "homehelp") {
800 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
801 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
802 if (translator_disabled) disp.setmacro ("textgotranslator", "home", "");
803
804 if (arg_p == "home") {
805 homepagestyle (disp, protos, args, logout);
806 } else if (arg_p == "homehelp") {
807 set_collectionlist_macro (disp, protos, logout);
808 }
809
810 } else if (arg_p == "homepref") {
811
812 // set _languageoption_ and _encodingoption_
813 set_language_encoding_macros(disp, args, protos, cinfo, logout);
814
815 } else if (arg_p == "preferences") {
816
817 if (cinfo == NULL) {
818 disp.setmacro("cvariable", "Global", arg_c);
819 disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
820 return;
821 }
822
823 if (collectproto == NULL) {return;}
824
825 // set _languageoption_ and _encodingoption_
826 set_language_encoding_macros(disp, args, protos, cinfo, logout);
827
828 // _collectionoption_
829 if ((args["ccs"] == "1") && (cinfo->ccsCols.size() > 1)) {
830 text_t collectionoption = "_textcollectionoption_";
831 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
832 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
833 int count = 0;
834 while (col_here != col_end) {
835 text_t colname;
836 if (*col_here == arg_c) {
837 colname = cinfo->collectionmeta["collectionname"];
838 } else {
839 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
840 if (this_cinfo == NULL) {col_here ++; continue;}
841 colname = this_cinfo->collectionmeta["collectionname"];
842 }
843
844 count ++;
845 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
846 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
847 colname + "<br>\n";
848 col_here ++;
849 }
850
851 if (count > 1)
852 disp.setmacro ("collectionoption", "preferences", collectionoption);
853 }
854
855 // _htmloptions_
856
857 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
858 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
859 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
860
861
862 // _PreferenceDocsFromWeb_
863
864 it = cinfo->format.find ("PreferenceDocsFromWeb");
865 if ((it == cinfo->format.end()) || ((*it).second == "true"))
866 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
867 }
868
869 // _prefschanged_
870 if (!args["bp"].empty()) {
871 disp.setmacro ("prefschanged", "preferences", "_textprefschanged_");
872 }
873
874 } else if (arg_p == "about" || arg_p == "help") {
875 if (collectproto == NULL) return;
876
877 comerror_t err;
878 bool has_search_button = true;
879 collectproto->is_searchable(args["c"], has_search_button, err, logout);
880 if (err != noError) has_search_button = true;
881
882 // _textbrowseoptions_ and _numbrowseoptions_
883
884 FilterResponse_t response;
885 text_tset metadata;
886 metadata.insert ("Title");
887 //****************
888 metadata.insert ("childtype");
889 //****************
890 bool getParents = false;
891 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
892
893 int numbrowseoptions = response.docInfo.size();
894 if (has_search_button) numbrowseoptions += 1;
895 disp.setmacro ("numbrowseoptions", "help", numbrowseoptions);
896
897 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
898 ResultDocInfo_tarray::iterator end = response.docInfo.end();
899
900 text_t shorttext;
901 text_t longtext;
902 if (has_search_button) {
903 shorttext = "<ul><li>_textSearchshort_\n";
904 longtext = "_textSearchlong_";
905 }
906
907 // ********************************
908 int classifiernumber = 0;
909 bool collage = false;
910
911 while (here != end) {
912
913 classifiernumber++;
914 text_t childtype = (*here).metadata["childtype"].values[0];
915 if (childtype == "Collage" && arg_p == "about") {
916 // get the classifier number
917 disp.setmacro ("classifier", "about", classifiernumber);
918 disp.setmacro ("aboutCollage", "about", "_collageapplet_");
919 collage = true;
920 }
921 here ++;
922 }
923 if (! collage)
924 disp.setmacro ("aboutCollage", "about", "_collageempty_");
925
926 // ********************************
927
928 here = response.docInfo.begin();
929
930 while (here != end) {
931
932 text_t title = (*here).metadata["Title"].values[0];
933
934 text_t stext, ltext;
935 disp.expandstring ("help", "_text" + title + "short_", stext);
936 if (stext == ("_text" + title + "short_")) {
937 shorttext += "<li>_help:textdefaultshorttext_";
938 longtext += "_help:textdefaultlongtext_";
939 } else {
940 shorttext += "<li>_help:text" + title + "short_";
941 longtext += "_help:text" + title + "long_";
942 }
943
944 here ++;
945 }
946 shorttext += "</ul>\n";
947 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
948 else disp.setmacro ("textbrowseoptions", "help", longtext);
949
950 if (arg_p == "about") {
951
952 // _textsubcollections_
953 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
954 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
955 text_tarray::const_iterator here = cinfo->ccsCols.begin();
956 text_tarray::const_iterator end = cinfo->ccsCols.end();
957 bool first = true;
958 int count = 0;
959 while (here != end) {
960 if (*here == arg_c) {
961 if (!first) textsubcollections += "<br>";
962 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
963 } else {
964 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
965 if (this_cinfo == NULL) {here ++; continue;}
966 if (!first) textsubcollections += "<br>";
967 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
968 }
969 count ++;
970 first = false;
971 here ++;
972 }
973 textsubcollections += "_textsubcols2_";
974 if (count > 1) {
975 disp.setmacro ("textsubcollections", "about", textsubcollections);
976 }
977 }
978
979 comerror_t err;
980 bool issearchable = true;
981 collectproto->is_searchable(args["c"], issearchable, err, logout);
982 if (err != noError) issearchable = true;
983 outconvertclass t;
984 if (!issearchable) {
985 disp.setmacro ("aboutqueryform", "about", "");
986 }
987 }
988
989 } else if (arg_p == "docs") {
990
991 set_documentation_macro (disp);
992
993 } else if (arg_p == "bsummary" && !arg_c.empty()) {
994
995 set_macro_to_file_contents (disp, "importlog", "bsummary",
996 filename_cat(gsdlhome, "collect", arg_c, "etc", "import.log"));
997 set_macro_to_file_contents (disp, "faillog", "bsummary",
998 filename_cat(gsdlhome, "collect", arg_c, "etc", "fail.log"));
999 }
1000}
1001
1002bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
1003 browsermapclass * /*browsers*/, displayclass &disp,
1004 outconvertclass &outconvert, ostream &textout,
1005 ostream &/*logout*/) {
1006
1007 text_t &arg_p = args["p"];
1008
1009 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
1010 << ("_" + arg_p + ":content_\n")
1011 << ("_" + arg_p + ":footer_\n");
1012
1013 return true;
1014}
1015
1016void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
1017 if ((key == "status") && (cfgline.size() == 1) &&
1018 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
1019 status_disabled = false;
1020 } else if ((key == "collector") && (cfgline.size() == 1) &&
1021 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
1022 collector_disabled = false;
1023 } else if ((key == "translator") && (cfgline.size() == 1) &&
1024 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
1025 translator_disabled = false;
1026 } else {
1027 // call the parent class to deal with the things which
1028 // are not dealt with here
1029 action::configure (key, cfgline);
1030 }
1031}
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
Note: See TracBrowser for help on using the repository browser.