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

Last change on this file since 11095 was 11095, checked in by jrm21, 18 years ago

move border=1 for logos in the collection list from receptionist into style
sheet.

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