source: gsdl/trunk/runtime-src/src/recpt/pageaction.cpp@ 18481

Last change on this file since 18481 was 18481, checked in by davidb, 15 years ago

missing space in attributes to html tag

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