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

Last change on this file since 5509 was 5509, checked in by mdewsnip, 21 years ago

Added check for invalid collection names for "about" pages. This is to avoid the otherwise-ugly "about" page that results when the collection doesn't exist. Will probably add the same check to other pages in the "page" action.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 31.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 collectionname = *collist_here;
217
218 if (get_info ("collection", *collist_here, metadata, false,
219 (*rprotolist_here).p, response, logout)) {
220 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
221 collectionname = response.docInfo[0].metadata["collectionname"].values[0];
222 }
223
224 comerror_t err;
225 text_t optsite = "";
226 text_t site_name = (*rprotolist_here).p->get_site_name (err);
227 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
228
229 text_t link = "_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type;
230 link += "&l=" + args["l"] + "&w=" + args["w"];
231
232 // We are "dynamically" overriding so to speak the
233 // link to the collection aka receptionist.
234
235 if (!cinfo->receptionist.empty())
236 link = cinfo->receptionist;
237
238
239 homeextra += "<option value=\"" + link + "\"";
240 homeextra += ">" + collectionname + "</option>\n";
241
242 }
243
244 collist_here ++;
245 }
246
247 }
248 }
249 rprotolist_here ++;
250 }
251
252 }
253 homeextra += "</select>\n";
254 homeextra += "</form>\n";
255
256 disp.setmacro ("homeextra", "home", homeextra);
257}
258
259// originally called set_homeextra_macro
260// this function displays the Greenstone
261// main page as usual with the graphics for
262// the collections.
263
264// Aly Dharshi
265// 11th July 2003
266
267void pageaction::home_images(displayclass &disp, recptprotolistclass *protos,
268 cgiargsclass &args, const recptconf &configinfo,
269 ostream &logout) {
270
271 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
272 bool found_valid_col = false;
273
274 recptprotolistclass::iterator rprotolist_here = protos->begin();
275 recptprotolistclass::iterator rprotolist_end = protos->end();
276 while (rprotolist_here != rprotolist_end) {
277 if ((*rprotolist_here).p != NULL) {
278
279 text_tarray collist;
280 comerror_t err;
281 (*rprotolist_here).p->get_collection_list (collist, err, logout);
282 if (err == noError) {
283 text_tarray::iterator collist_here = collist.begin();
284 text_tarray::iterator collist_end = collist.end();
285
286 int count = 0;
287 bool first = true;
288 while (collist_here != collist_end) {
289 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
290
291 if (cinfo != NULL) {
292 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
293
294 text_t coll_type = "&ct=";
295 if (cinfo->buildType == "mgpp") {
296 coll_type += "1&qto=";
297
298 // now we also want to check search types to set the qto arg
299 if (cinfo->searchTypes.size() == 0) {
300 coll_type += "3"; // default to 3 (= both)
301 } else {
302 unsigned int search_types = 0;
303 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
304 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
305
306 while (type_here != type_end) {
307 if (*type_here == "form") {
308 search_types |= 2;
309 } else if (*type_here == "plain") {
310 search_types |= 1;
311 }
312 type_here ++;
313 }
314 coll_type += search_types;
315 if (search_types == 3) {
316 // both were specified, now need to look at the order to see which is the default
317 type_here = cinfo->searchTypes.begin();
318 if (*type_here == "form") {
319 coll_type += "&qt=1"; // set the default to form
320 }
321 }
322
323 }
324 }
325 else {
326 coll_type += "0";
327 }
328
329 found_valid_col = true;
330 FilterResponse_t response;
331 text_tset metadata;
332 metadata.insert ("collectionname");
333 metadata.insert ("iconcollection");
334 metadata.insert ("iconcollectionsmall");
335 text_t collectionname = *collist_here;
336 text_t alt = collectionname;
337
338 if (get_info ("collection", *collist_here, metadata, false,
339 (*rprotolist_here).p, response, logout)) {
340 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
341 alt = response.docInfo[0].metadata["collectionname"].values[0];
342
343 text_t iconurl;
344 iconurl.clear();
345
346 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) {
347 iconurl = response.docInfo[0].metadata["iconcollectionsmall"].values[0];
348 } else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) {
349 iconurl = response.docInfo[0].metadata["iconcollection"].values[0];
350 }
351
352 if (!iconurl.empty())
353 {
354 // check to see URL is local to colserver
355 text_t::iterator iconurl_head = iconurl.begin();
356 text_t iconhead = substr(iconurl_head,iconurl_head+16);
357 if (iconhead=="_httpcollection_")
358 {
359 // local and using _httpcollection_
360 text_t icontail = substr(iconurl_head+16,iconurl.end());
361 iconurl = "http://" + cinfo->httpdomain
362 + cinfo->httpprefix + "/collect/"
363 + *collist_here + "/" + icontail;
364 }
365 else if (iconurl[0]=='/')
366 {
367 // local but with full path
368 iconurl = "http://" + cinfo->httpdomain + iconurl;
369 }
370
371 collectionname
372 = "<img width=150 border=1 src=\"" + iconurl + "\" alt=\"" + alt + "\">";
373 }
374 else
375 {
376 collectionname = alt;
377 }
378
379 }
380 if ((count%configinfo.HomePageCols == 0) && (!first))
381 homeextra += "</tr><tr valign=top>\n";
382
383 comerror_t err;
384 text_t optsite = "";
385 text_t site_name = (*rprotolist_here).p->get_site_name (err);
386 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
387
388 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type;
389 link += "&l=" + args["l"] + "&w=" + args["w"] + "\">";
390
391 if (!cinfo->receptionist.empty())
392 link = "<a href=\"" + cinfo->receptionist + "\">";
393
394 homeextra += "<td>" + link + collectionname + "</a></td>\n";
395
396 count ++;
397 first = false;
398 }
399 }
400 collist_here ++;
401 }
402
403 for (; count%configinfo.HomePageCols != 0; count ++) homeextra += "<td></td>\n";
404 }
405 }
406 homeextra += "</td></tr>\n<tr>\n";
407 rprotolist_here ++;
408 }
409
410 if (!found_valid_col) {
411 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
412 }
413 homeextra += "</tr></table></center>\n";
414 disp.setmacro ("homeextra", "home", homeextra);
415}
416
417void pageaction::set_collectionlist_macro (displayclass &disp, recptprotolistclass *protos,
418 ostream &logout) {
419
420 text_t collectionlist;
421 int count = 0;
422
423 recptprotolistclass::iterator rprotolist_here = protos->begin();
424 recptprotolistclass::iterator rprotolist_end = protos->end();
425 while (rprotolist_here != rprotolist_end) {
426 if ((*rprotolist_here).p != NULL) {
427
428 text_tarray collist;
429 comerror_t err;
430 (*rprotolist_here).p->get_collection_list (collist, err, logout);
431 if (err == noError) {
432 text_tarray::iterator collist_here = collist.begin();
433 text_tarray::iterator collist_end = collist.end();
434
435 while (collist_here != collist_end) {
436 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
437
438 if (cinfo != NULL) {
439 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
440
441 count ++;
442
443 text_t coll_type = "&ct=";
444 if (cinfo->buildType == "mgpp") {
445 coll_type += "1&qto=";
446
447 // now we also want to check search types to set the qto arg
448 if (cinfo->searchTypes.size() == 0) {
449 coll_type += "3"; // default to 2 (= both)
450 } else {
451 int search_types = 0;
452 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
453 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
454
455 while (type_here != type_end) {
456 if (*type_here == "form") {
457 search_types |= 0x10;
458 } else if (*type_here == "plain") {
459 search_types |= 0x01;
460 }
461 type_here ++;
462 }
463 coll_type += search_types;
464
465 if (search_types == 3) {
466 // both were specified, now need to look at the order to see which is the default
467 type_here = cinfo->searchTypes.begin();
468 if (*type_here == "form") {
469 coll_type += "&qt=1"; // set the default to form
470 }
471 }
472 }
473 }
474 else {
475 coll_type += "0";
476 }
477 FilterResponse_t response;
478 text_tset metadata;
479 metadata.insert ("collectionname");
480 text_t collectionname = *collist_here;
481
482 if (get_info ("collection", *collist_here, metadata, false,
483 (*rprotolist_here).p, response, logout)) {
484 if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
485 collectionname = response.docInfo[0].metadata["collectionname"].values[0];
486 }
487 }
488
489 comerror_t err;
490 text_t optsite = "";
491 text_t site_name = (*rprotolist_here).p->get_site_name (err);
492 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
493
494 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type+"\">";
495
496 if (!cinfo->receptionist.empty())
497 link = "<a href=\"" + cinfo->receptionist + "\">";
498
499 collectionlist += "<li>" + link + collectionname + "</a>\n";
500 }
501 }
502 collist_here ++;
503 }
504 }
505 }
506 rprotolist_here ++;
507 }
508
509 if (count == 1) {
510 collectionlist = "<p>_text1coll_\n<ul>" +
511 collectionlist + "</ul>\n";
512 } else if (count > 1) {
513 collectionlist = "<p>_textmorecolls_(" + text_t(count) +
514 ")\n<ul>" + collectionlist + "</ul>\n";
515 }
516
517 disp.setmacro ("collectionlist", "homehelp", collectionlist);
518}
519
520void pageaction::set_documentation_macro (displayclass &disp) {
521
522 text_t documentation;
523 text_t docsdir = filename_cat(gsdlhome, "docs");
524
525 if (file_exists(filename_cat(docsdir, "User.pdf"))) {
526 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/User.pdf\">_iconpdf_"
527 "</a></td><td>_textuserguide_</td></tr>";
528 }
529
530 if (file_exists(filename_cat(docsdir, "Install.pdf"))) {
531 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Install.pdf\">_iconpdf_"
532 "</a></td><td>_textinstallerguide_</td></tr>";
533 }
534
535 if (file_exists(filename_cat(docsdir, "Develop.pdf"))) {
536 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Develop.pdf\">_iconpdf_"
537 "</a></td><td>_textdeveloperguide_</td></tr>";
538 }
539
540 if (file_exists(filename_cat(docsdir, "Paper.pdf"))) {
541 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Paper.pdf\">_iconpdf_"
542 "</a></td><td>_textpaperguide_</td></tr>";
543 }
544
545 if (!documentation.empty()) {
546 disp.setmacro("documentation", "docs", "<p>\n<table border=0>\n" + documentation + "\n</table>\n");
547 }
548}
549
550void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
551 const text_t &packagename, const text_t &filename) {
552
553 text_t filecontent;
554 char *filenamec = filename.getcstr();
555 ifstream file_in (filenamec);
556 delete filenamec;
557 if (file_in) {
558 char c;
559 file_in.get(c);
560 while (!file_in.eof ()) {
561 if (c == '\n') filecontent += "<br>";
562 filecontent.push_back(c);
563 file_in.get(c);
564 }
565 file_in.close();
566 }
567 disp.setmacro (macroname, packagename, dm_safe(filecontent));
568}
569
570void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
571 recptprotolistclass *protos, ColInfoResponse_t *cinfo,
572 ostream &logout) {
573 // _languageoption_
574 // Create the "interface language" selection box for the preferences
575 // pages. You can use something like "format PreferenceLanguages
576 // en|fr|zn" from within a collect.cfg file to use only a subset of
577 // the available languages for any given collection (for
578 // collection-specific preferences pages). This facility is kind of
579 // ugly though and should be replaced by something better when the
580 // configuration files are tidied up (as should all the other
581 // "format Preference..." options).
582 text_t &arg_l = args["l"];
583 const recptconf &configinfo = recpt->get_configinfo();
584 // put languages in another map to sort them by longname
585 text_tmap languages;
586 languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
587 languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
588 while (thislang != endlang) {
589 languages[(*thislang).second.longname] = (*thislang).first;
590 thislang++;
591 }
592 text_tmap::iterator tlang = languages.begin();
593 text_tmap::iterator elang = languages.end();
594
595 text_t languageoption;
596 bool collection_specific = false;
597
598 if (cinfo != NULL) {
599 text_tmap::const_iterator it = cinfo->format.find ("PreferenceLanguages");
600 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
601 collection_specific = true;
602 text_tset pref_langs;
603 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
604 if (pref_langs.size() > 1) {
605 while (tlang != elang) {
606 if (pref_langs.find((*tlang).second) != pref_langs.end()) {
607 languageoption += "<option value=\"" + (*tlang).second + "\"";
608 if ((*tlang).second == arg_l) languageoption += " selected";
609 languageoption += ">" + (*tlang).first + "\n";
610 }
611 tlang ++;
612 }
613 }
614 }
615 }
616
617 if (!collection_specific) {
618 while (tlang != elang) {
619 languageoption += "<option value=\"" + (*tlang).second + "\"";
620 if ((*tlang).second == arg_l) languageoption += " selected";
621 languageoption += ">" + (*tlang).first + "\n";
622 tlang ++;
623 }
624 }
625
626 if (!languageoption.empty()) {
627 languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
628 languageoption += "</select>\n";
629 disp.setmacro ("languageoption", args["p"], languageoption);
630 }
631
632 // _encodingoption_
633 // create the "encoding" selection box for the preferences page
634 if (configinfo.encodings.size() > 1) {
635 text_t &arg_w = args["w"];
636 text_t encodingoption;
637 text_tmap::const_iterator thisenc = configinfo.encodings.begin();
638 text_tmap::const_iterator endenc = configinfo.encodings.end();
639 while (thisenc != endenc) {
640 encodingoption += "<option value=\"" + (*thisenc).second + "\"";
641 if ((*thisenc).second == arg_w) encodingoption += " selected";
642 encodingoption += ">" + (*thisenc).first + "\n";
643 thisenc ++;
644 }
645
646 encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
647 encodingoption += "</select>\n";
648 disp.setmacro ("encodingoption", args["p"], encodingoption);
649 }
650}
651
652void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
653 recptprotolistclass *protos, ostream &logout) {
654
655 // define_internal_macros sets the following macros:
656
657 // _numdocs_ the number of documents in the collection
658
659 // _builddate_ the date last built
660
661 // if page is "home"
662 // _homeextra_ this is the list of available collections and collection info
663 // to be displayed on the home page
664
665
666 // if page is "preferences"
667 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
668
669 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
670
671 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
672
673
674 // if page is "preferences" or "homepref"
675 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
676
677 // _encodingoption_ encodings to select from
678
679
680 // if page is "about"
681 // _textsubcollections_ the text on which subcollections make up the collection (if
682 // cross-collection searching is being used
683
684 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
685
686 // _numbrowseoptions_ the number of browsing options
687
688 // _prefschanged_ will be set to _textprefschanged_ if the "set preferences" button
689 // was pressed
690
691 // _aboutqueryform_ will be set to "" if the collection isn't searchable
692
693 // if page is "help"
694 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
695
696 // _numbrowseoptions_ the number of browsing options
697
698 // _topicreadingdocs_ this section of the help text differs depending on what type of
699 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
700 // _texthelpreadingdocs_
701
702 // if page is "home" or "homehelp"
703 // _textgocollector_ set to "" if collector is disabled in main.cfg
704 // _textgoadmin_ set to "" if status is disabled in main.cfg
705 // _textgotranslator_ set to "" if translator is disabled in main.cfg
706
707
708 // if page is "homehelp"
709 // _collectionlist_ list of available collections to be displayed on the homehelp page
710
711
712 // if page is "docs"
713 // _documentation_ links to PDF documents if they're available
714
715
716 // if page is "bsummary"
717 // _importlog_ set to contents of collections import.log file
718 // _faillog_ set to contents of collections fail.log file
719
720
721 if (recpt == NULL) {
722 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
723 << " information about any receptionists. The method set_receptionist was\n"
724 << " probably not called from the module which instantiated this action.\n";
725 return;
726 }
727
728 text_t &arg_p = args["p"];
729 text_t &arg_c = args["c"];
730 ColInfoResponse_t *cinfo = NULL;
731
732 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
733 if (collectproto != NULL) {
734 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
735
736 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
737 unsigned long current_time = time(NULL);
738 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
739 disp.setmacro ("builddate", "Global", builddate);
740
741 text_t numbytes;
742 if ((cinfo->numBytes/(1024*1024)) > 1) {
743 numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
744 } else if ((cinfo->numBytes/1024) > 1) {
745 numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
746 } else {
747 numbytes = (text_t)cinfo->numBytes + " bytes";
748 }
749 disp.setmacro("numbytes", "Global", numbytes);
750 }
751
752 //setting _queryformcontent_ so that the query interface is consistent.
753 //also adding usability button if necessary
754 if (arg_p == "about") {
755 if (cinfo == NULL) {
756 disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
757 return;
758 }
759 else {
760 text_tmap::iterator check = cinfo->format.find("QueryInterface");
761 if(check != cinfo->format.end()){
762 if((*check).second=="DateSearch"){
763 text_t current = "_basicqueryform_ _datesearch_";
764
765 disp.setmacro("queryformcontent","query",current);
766 }
767 }
768 check = cinfo->format.find("Usability");
769 if(check != cinfo->format.end()){
770 disp.setmacro("usability","Global","_imageusab_");
771 disp.setmacro("usabinterface","Global",("_usab"+(*check).second+"_"));
772 disp.setmacro("usabilityscript", "Global", "_usabshowscript_");
773 }
774 }
775 }
776
777 if (arg_p == "home" || arg_p == "homehelp") {
778 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
779 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
780 if (translator_disabled) disp.setmacro ("textgotranslator", "home", "");
781
782 if (arg_p == "home") {
783 homepagestyle (disp, protos, args, logout);
784 } else if (arg_p == "homehelp") {
785 set_collectionlist_macro (disp, protos, logout);
786 }
787
788 } else if (arg_p == "homepref") {
789
790 // set _languageoption_ and _encodingoption_
791 set_language_encoding_macros(disp, args, protos, cinfo, logout);
792
793 } else if (arg_p == "preferences") {
794 if (collectproto == NULL) {return;}
795
796 // set _languageoption_ and _encodingoption_
797 set_language_encoding_macros(disp, args, protos, cinfo, logout);
798
799 // _collectionoption_
800
801 if ((args["ccs"] == "1") && (cinfo->ccsCols.size() > 1)) {
802 text_t collectionoption = "_textcollectionoption_";
803 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
804 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
805 int count = 0;
806 while (col_here != col_end) {
807 text_t colname;
808 if (*col_here == arg_c) {
809 colname = cinfo->collectionmeta["collectionname"];
810 } else {
811 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
812 if (this_cinfo == NULL) {col_here ++; continue;}
813 colname = this_cinfo->collectionmeta["collectionname"];
814 }
815
816 count ++;
817 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
818 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
819 colname + "<br>\n";
820 col_here ++;
821 }
822
823 if (count > 1)
824 disp.setmacro ("collectionoption", "preferences", collectionoption);
825 }
826
827 // _htmloptions_
828
829 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
830 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
831 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
832
833
834 // _PreferenceDocsFromWeb_
835
836 it = cinfo->format.find ("PreferenceDocsFromWeb");
837 if ((it == cinfo->format.end()) || ((*it).second == "true"))
838 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
839 }
840
841 // _prefschanged_
842 if (!args["bp"].empty()) {
843 disp.setmacro ("prefschanged", "preferences", "_textprefschanged_");
844 }
845
846 } else if (arg_p == "about" || arg_p == "help") {
847 if (collectproto == NULL) return;
848
849 comerror_t err;
850 bool has_search_button = true;
851 collectproto->is_searchable(args["c"], has_search_button, err, logout);
852 if (err != noError) has_search_button = true;
853
854 // _textbrowseoptions_ and _numbrowseoptions_
855
856 FilterResponse_t response;
857 text_tset metadata;
858 metadata.insert ("Title");
859 bool getParents = false;
860 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
861
862 int numbrowseoptions = response.docInfo.size();
863 if (has_search_button) numbrowseoptions += 1;
864 disp.setmacro ("numbrowseoptions", "help", numbrowseoptions);
865
866 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
867 ResultDocInfo_tarray::iterator end = response.docInfo.end();
868
869 text_t shorttext;
870 text_t longtext;
871 if (has_search_button) {
872 shorttext = "<ul><li>_textSearchshort_\n";
873 longtext = "_textSearchlong_";
874 }
875
876 while (here != end) {
877 text_t title = (*here).metadata["Title"].values[0];
878
879 text_t stext, ltext;
880 disp.expandstring ("help", "_text" + title + "short_", stext);
881 if (stext == ("_text" + title + "short_")) {
882 shorttext += "<li>_help:textdefaultshorttext_";
883 longtext += "_help:textdefaultlongtext_";
884 } else {
885 shorttext += "<li>_help:text" + title + "short_";
886 longtext += "_help:text" + title + "long_";
887 }
888
889 here ++;
890 }
891 shorttext += "</ul>\n";
892 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
893 else disp.setmacro ("textbrowseoptions", "help", longtext);
894
895 if (arg_p == "about") {
896
897 // _textsubcollections_
898 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
899 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
900 text_tarray::const_iterator here = cinfo->ccsCols.begin();
901 text_tarray::const_iterator end = cinfo->ccsCols.end();
902 bool first = true;
903 int count = 0;
904 while (here != end) {
905 if (*here == arg_c) {
906 if (!first) textsubcollections += "<br>";
907 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
908 } else {
909 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
910 if (this_cinfo == NULL) {here ++; continue;}
911 if (!first) textsubcollections += "<br>";
912 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
913 }
914 count ++;
915 first = false;
916 here ++;
917 }
918 textsubcollections += "_textsubcols2_";
919 if (count > 1) {
920 disp.setmacro ("textsubcollections", "about", textsubcollections);
921 }
922 }
923
924 comerror_t err;
925 bool issearchable = true;
926 collectproto->is_searchable(args["c"], issearchable, err, logout);
927 if (err != noError) issearchable = true;
928 outconvertclass t;
929 if (!issearchable) {
930 disp.setmacro ("aboutqueryform", "about", "");
931 }
932 }
933
934 } else if (arg_p == "docs") {
935
936 set_documentation_macro (disp);
937
938 } else if (arg_p == "bsummary" && !arg_c.empty()) {
939
940 set_macro_to_file_contents (disp, "importlog", "bsummary",
941 filename_cat(gsdlhome, "collect", arg_c, "etc", "import.log"));
942 set_macro_to_file_contents (disp, "faillog", "bsummary",
943 filename_cat(gsdlhome, "collect", arg_c, "etc", "fail.log"));
944 }
945}
946
947bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
948 browsermapclass * /*browsers*/, displayclass &disp,
949 outconvertclass &outconvert, ostream &textout,
950 ostream &/*logout*/) {
951
952 text_t &arg_p = args["p"];
953
954 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
955 << ("_" + arg_p + ":content_\n")
956 << ("_" + arg_p + ":footer_\n");
957
958 return true;
959}
960
961void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
962 if ((key == "status") && (cfgline.size() == 1) &&
963 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
964 status_disabled = false;
965 } else if ((key == "collector") && (cfgline.size() == 1) &&
966 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
967 collector_disabled = false;
968 } else if ((key == "translator") && (cfgline.size() == 1) &&
969 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
970 translator_disabled = false;
971 } else {
972 // call the parent class to deal with the things which
973 // are not dealt with here
974 action::configure (key, cfgline);
975 }
976}
977
978
979
980
981
982
983
984
985
986
Note: See TracBrowser for help on using the repository browser.