source: main/trunk/greenstone2/runtime-src/src/recpt/pageaction.cpp@ 22984

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