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

Last change on this file since 1276 was 1276, checked in by nzdl, 24 years ago

added an error message when no "valid" collections are available

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 19.1 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 * $Id: pageaction.cpp 1276 2000-07-12 04:51:05Z nzdl $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.34 2000/07/12 04:51:05 nzdl
31 added an error message when no "valid" collections are available
32
33 Revision 1.33 2000/07/05 21:49:33 sjboddie
34 Receptionist now caches collection information to avoid making multiple
35 get_collectinfo calls to collection server
36
37 Revision 1.32 2000/06/27 23:02:40 sjboddie
38 Tidied up the way collections are displayed on 'standard' homepage.
39 Removed all the nzdl.org specific stuff.
40
41 Revision 1.31 2000/06/23 03:48:08 sjboddie
42 Added Arabic language and encoding options to the preferences page. This
43 is a much more complex task than it should be (you even have to recompile!)
44 but it's not really worth fixing until the new config file format is
45 finalised.
46
47 Revision 1.30 2000/06/14 22:33:42 sjboddie
48 Added French and Spanish language selection options to the preferences
49 page. I really don't like how this is currently implemented (i.e. you
50 have to recompile the library to do something so simple), it might have
51 to wait until the new configuration file stuff is done before it's fixed
52 though.
53
54 Revision 1.29 2000/03/19 21:16:46 nzdl
55 added german language interface
56
57 Revision 1.28 2000/02/24 01:19:01 sjboddie
58 fixed up messy hack for meldex
59
60 Revision 1.27 2000/02/15 22:53:51 kjm18
61 search history stuff added.
62
63 Revision 1.26 2000/02/03 01:49:35 sjboddie
64 fixed up some of the preferences stuff
65
66 Revision 1.25 2000/01/26 20:11:04 sjboddie
67 added some collection specific help text
68
69 Revision 1.24 2000/01/25 22:31:09 sjboddie
70 more hacky changes to get preferences to be a bit smarter
71
72 Revision 1.23 2000/01/24 22:59:57 sjboddie
73 changes to set macros differently for preferences page depending
74 on type of collection - pageaction is getting kind of hacky - should
75 tidy it up some day
76
77 Revision 1.22 1999/11/25 23:01:09 sjboddie
78 now need to be able to handle it if no collection is selected
79
80 Revision 1.21 1999/11/03 22:50:13 sjboddie
81 now defaults to home page
82
83 Revision 1.20 1999/11/01 21:58:02 sjboddie
84 changes to arguments of many functions, now pass list of protocols
85 instead of just that for this collection
86
87 Revision 1.19 1999/10/19 21:59:09 sjboddie
88 bug in generating "how to find information" text for about pages
89
90 Revision 1.18 1999/10/19 03:23:44 davidb
91 Collection building support through web pages
92 and internal and external link handling for collection documents
93
94 Revision 1.17 1999/10/14 23:04:44 sjboddie
95 some hacks to make nzdl home page look right
96
97 Revision 1.16 1999/10/10 08:14:09 sjboddie
98 - metadata now returns mp rather than array
99 - redesigned browsing support (although it's not finished so
100 won't currently work ;-)
101
102 Revision 1.15 1999/09/17 04:46:05 sjboddie
103 fixed a couple of problems with 'unknown' classifier
104
105 Revision 1.14 1999/09/07 23:08:09 rjmcnab
106 Removed some compiler warnings
107
108 Revision 1.13 1999/09/07 04:56:57 sjboddie
109 added GPL notice
110
111 Revision 1.12 1999/09/02 00:26:43 rjmcnab
112 made the p cgi argument always saved in the compressed arguments
113
114 Revision 1.11 1999/08/25 04:48:43 sjboddie
115 changes to the home and about pages
116
117 Revision 1.10 1999/08/11 23:29:43 sjboddie
118 added support for html classifier (i.e. the hp argument)
119
120 Revision 1.9 1999/08/03 03:29:47 sjboddie
121 added ability to set receptionist from collect.cfg
122
123 Revision 1.8 1999/07/30 02:24:44 sjboddie
124 added collectinfo argument to some functions
125
126 Revision 1.7 1999/06/24 05:12:24 sjboddie
127 lots of small changes
128
129 Revision 1.6 1999/06/10 00:39:16 sjboddie
130 navigation bar is no longer written out for every page (it should
131 be included in the _content_ macro of pages wanting to display it).
132
133 Revision 1.5 1999/06/08 04:29:35 sjboddie
134 added argsinfo to the call to check_cgiargs to make it easy to set
135 args to their default if they're found to be screwed up
136
137 Revision 1.4 1999/02/28 20:00:14 rjmcnab
138
139
140 Fixed a few things.
141
142 Revision 1.3 1999/02/25 21:58:58 rjmcnab
143
144 Merged sources.
145
146 Revision 1.2 1999/02/21 22:33:54 rjmcnab
147
148 Lots of stuff :-)
149
150 Revision 1.1 1999/02/12 02:40:17 sjboddie
151
152 Added page action
153
154 */
155
156#include "OIDtools.h"
157#include "pageaction.h"
158#include "receptionist.h"
159#include <time.h>
160
161pageaction::pageaction () {
162
163 recpt = NULL;
164
165 // this action uses cgi variables "a", "p", and "hp"
166 cgiarginfo arg_ainfo;
167 arg_ainfo.shortname = "a";
168 arg_ainfo.longname = "action";
169 arg_ainfo.multiplechar = true;
170 arg_ainfo.defaultstatus = cgiarginfo::weak;
171 arg_ainfo.argdefault = "p";
172 arg_ainfo.savedarginfo = cgiarginfo::must;
173 argsinfo.addarginfo (NULL, arg_ainfo);
174
175 arg_ainfo.shortname = "p";
176 arg_ainfo.longname = "page";
177 arg_ainfo.multiplechar = true;
178 arg_ainfo.defaultstatus = cgiarginfo::weak;
179 arg_ainfo.argdefault = "home";
180 arg_ainfo.savedarginfo = cgiarginfo::must;
181 argsinfo.addarginfo (NULL, arg_ainfo);
182
183 arg_ainfo.shortname = "hp";
184 arg_ainfo.longname = "html page";
185 arg_ainfo.multiplechar = true;
186 arg_ainfo.defaultstatus = cgiarginfo::weak;
187 arg_ainfo.argdefault = "";
188 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
189 argsinfo.addarginfo (NULL, arg_ainfo);
190}
191
192pageaction::~pageaction () {
193}
194
195bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
196 ostream &/*logout*/) {
197 // don't want to check anything yet.
198 return true;
199}
200
201void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
202 response_t &response,text_t &response_data,
203 ostream &/*logout*/) {
204 response = content;
205 response_data = "text/html";
206}
207
208void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
209 ostream &logout) {
210
211 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
212 bool found_valid_col = false;
213
214 recptprotolistclass::iterator rprotolist_here = protos->begin();
215 recptprotolistclass::iterator rprotolist_end = protos->end();
216 while (rprotolist_here != rprotolist_end) {
217 if ((*rprotolist_here).p != NULL) {
218
219 text_tarray collist;
220 comerror_t err;
221 (*rprotolist_here).p->get_collection_list (collist, err, logout);
222 if (err == noError) {
223 text_tarray::iterator collist_here = collist.begin();
224 text_tarray::iterator collist_end = collist.end();
225
226 int count = 0;
227 bool first = true;
228 while (collist_here != collist_end) {
229
230 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
231
232 if (cinfo != NULL) {
233 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
234
235 found_valid_col = true;
236 FilterResponse_t response;
237 text_tset metadata;
238 metadata.insert ("collectionname");
239 metadata.insert ("iconcollection");
240 metadata.insert ("iconcollectionsmall");
241 text_t collectionname = *collist_here;
242 text_t alt = collectionname;
243 if (get_info ("collection", *collist_here, metadata, false,
244 (*rprotolist_here).p, response, logout)) {
245 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
246 alt = response.docInfo[0].metadata["collectionname"].values[0];
247
248 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
249 collectionname = "<img width=150 border=1 src=\""
250 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
251 + "\" alt=\"" + alt + "\">";
252 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
253 collectionname = "<img width=150 border=1 src=\""
254 + response.docInfo[0].metadata["iconcollection"].values[0]
255 + "\" alt=\"" + alt + "\">";
256 else collectionname = alt;
257 }
258
259 if ((count%3 == 0) && (!first))
260 homeextra += "</tr><tr valign=top>\n";
261
262 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
263 if (*collist_here == "chinese")
264 link = "<a href=\"_gwcgi_?a=p&p=about&l=zh&nw=u&c=" + *collist_here + "\">";
265 if (*collist_here == "arabic")
266 link = "<a href=\"_gwcgi_?a=p&p=about&l=ar&nw=u&c=" + *collist_here + "\">";
267
268 if (!cinfo->receptionist.empty())
269 link = "<a href=\"" + cinfo->receptionist + "\">";
270
271 homeextra += "<td>" + link + collectionname + "</a></td>\n";
272
273 count ++;
274 first = false;
275 }
276 }
277
278 collist_here ++;
279 }
280 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
281 }
282 }
283 rprotolist_here ++;
284 }
285
286 if (!found_valid_col) {
287 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
288 }
289 homeextra += "</tr></table></center>\n";
290 disp.setmacro ("homeextra", "home", homeextra);
291
292}
293
294void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
295 recptprotolistclass *protos, ostream &logout) {
296
297 // define_internal_macros sets the following macros:
298
299 // _numdocs_ the number of documents in the collection
300
301 // _builddate_ the date last built
302
303
304 // if page is "home"
305 // _homeextra_ this is the list of available collections and collection info
306 // to be displayed on the home page
307
308
309 // if page is "preferences"
310 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
311
312 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
313
314 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
315
316 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
317
318 // _encodingoption_ will be overridden to "" if chinese language interface isn't specified
319
320 // if page is "about"
321 // _textsubcollections_ the text on which subcollections make up the collection (if
322 // cross-collection searching is being used
323
324 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
325
326 // _numbrowseoptions_ the number of browsing options
327
328
329 // if page is "help"
330 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
331
332 // _numbrowseoptions_ the number of browsing options
333
334 // _topicreadingdocs_ this section of the help text differs depending on what type of
335 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
336 // _texthelpreadingdocs_
337
338
339 if (recpt == NULL) {
340 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
341 << " information about any receptionists. The method set_receptionist was\n"
342 << " probably not called from the module which instantiated this action.\n";
343 return;
344 }
345
346 text_t &arg_p = args["p"];
347 text_t &arg_c = args["c"];
348 ColInfoResponse_t *cinfo = NULL;
349
350 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
351 if (collectproto != NULL) {
352 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
353
354 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
355 unsigned long current_time = time(NULL);
356 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
357 disp.setmacro ("builddate", "Global", builddate);
358 }
359
360 if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
361
362 else if (arg_p == "preferences") {
363
364 // _collectionoption_
365
366 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
367 text_t collectionoption = "_textcollectionoption_";
368 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
369 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
370 int count = 0;
371 while (col_here != col_end) {
372 text_t colname;
373 if (*col_here == arg_c) {
374 colname = cinfo->collectionmeta["collectionname"];
375 } else {
376 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
377 if (this_cinfo == NULL) {col_here ++; continue;}
378 colname = this_cinfo->collectionmeta["collectionname"];
379 }
380
381 count ++;
382 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
383 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
384 colname + "<br>\n";
385 col_here ++;
386 }
387
388 if (count > 1)
389 disp.setmacro ("collectionoption", "preferences", collectionoption);
390 }
391
392 // _htmloptions_
393
394 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
395 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
396 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
397
398
399 // _PreferenceDocsFromWeb_
400
401 it = cinfo->format.find ("PreferenceDocsFromWeb");
402 if ((it == cinfo->format.end()) || ((*it).second == "true"))
403 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
404 }
405
406 // _languageoption_
407 // this is kind of a hack (another one!!). note that there're potential
408 // problems here as no checking is done anywhere to make sure language
409 // is set to a valid value. this does allow us to set which languages
410 // should go in the preference selection box (from collect.cfg) however
411 // and that's sufficient for current requirements
412
413 // currently supported languages (_languageoption_ will default to all
414 // these languages unless PreferenceLanguages is set
415 text_tarray languages;
416 languages.push_back ("en");
417 languages.push_back ("fr");
418 languages.push_back ("de");
419 languages.push_back ("es");
420 languages.push_back ("mi");
421 languages.push_back ("zh");
422 languages.push_back ("ar");
423 text_tarray::const_iterator this_lang = languages.begin();
424 text_tarray::const_iterator end_lang = languages.end();
425
426 text_t languageoption = "_textlanguage_\n<select name=\"l\" onChange=\"updatel();\">\n";
427 it = cinfo->format.find ("PreferenceLanguages");
428 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
429 text_tset pref_langs;
430 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
431 if (pref_langs.size() > 1) {
432 while (this_lang != end_lang) {
433 if (pref_langs.find(*this_lang) != pref_langs.end())
434 languageoption += "_" + *this_lang + "languageoption_\n";
435 this_lang ++;
436 }
437 languageoption += "</select>\n";
438 disp.setmacro ("languageoption", "preferences", languageoption);
439 }
440
441 // _encodingoption_
442
443 if (pref_langs.find("zh") == pref_langs.end())
444 disp.setmacro ("encodingoption", "preferences", "");
445
446 } else {
447 while (this_lang != end_lang) {
448 languageoption += "_" + *this_lang + "languageoption_\n";
449 this_lang ++;
450 }
451 languageoption += "</select>\n";
452 disp.setmacro ("languageoption", "preferences", languageoption);
453 }
454
455 } else if (arg_p == "about" || arg_p == "help") {
456 if (collectproto == NULL) return;
457
458 // _textbrowseoptions_ and _numbrowseoptions_
459
460 FilterResponse_t response;
461 text_tset metadata;
462 metadata.insert ("Title");
463 bool getParents = false;
464 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
465
466 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
467
468 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
469 ResultDocInfo_tarray::iterator end = response.docInfo.end();
470
471 // we're assuming that we've always got a search button
472 text_t shorttext = "<ul><li>_textSearchshort_\n";
473 text_t longtext = "_textSearchlong_";
474
475 while (here != end) {
476 text_t title = (*here).metadata["Title"].values[0];
477
478 text_t stext, ltext;
479 disp.expandstring ("help", "_text" + title + "short_", stext);
480 if (stext == ("_text" + title + "short_")) {
481 shorttext += "<li>_help:textdefaultshorttext_";
482 longtext += "_help:textdefaultlongtext_";
483 } else {
484 shorttext += "<li>" + stext;
485 longtext += "_help:text" + title + "long_";
486 }
487
488 here ++;
489 }
490 shorttext += "</ul>\n";
491 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
492 else disp.setmacro ("textbrowseoptions", "help", longtext);
493
494 if (arg_p == "help") {
495
496 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
497
498 // if HTML collection there's no how to read document text
499 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
500 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
501 disp.setmacro ("topicreadingdocs", "help", "");
502 disp.setmacro ("texthelpreadingdocs", "help", "");
503 }
504 it = cinfo->format.find ("HelpBibDocs");
505 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
506 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
507 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
508 }
509 it = cinfo->format.find ("HelpBookDocs");
510 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
511 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
512 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
513 }
514
515 }
516 if (arg_p == "about") {
517
518 // _textsubcollections_
519 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
520 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
521 text_tarray::const_iterator here = cinfo->ccsCols.begin();
522 text_tarray::const_iterator end = cinfo->ccsCols.end();
523 bool first = true;
524 int count = 0;
525 while (here != end) {
526 if (*here == arg_c) {
527 if (!first) textsubcollections += "<br>";
528 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
529 } else {
530 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
531 if (this_cinfo == NULL) {here ++; continue;}
532 if (!first) textsubcollections += "<br>";
533 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
534 }
535 count ++;
536 first = false;
537 here ++;
538 }
539 textsubcollections += "_textsubcols2_";
540 if (count > 1)
541 disp.setmacro ("textsubcollections", "about", textsubcollections);
542 }
543 }
544 }
545}
546
547bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
548 browsermapclass * /*browsers*/, displayclass &disp,
549 outconvertclass &outconvert, ostream &textout,
550 ostream &/*logout*/) {
551
552 text_t &arg_p = args["p"];
553
554 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
555 << ("_" + arg_p + ":content_\n")
556 << ("_" + arg_p + ":footer_\n");
557
558 return true;
559}
560
561
562
563
564
Note: See TracBrowser for help on using the repository browser.