source: branches/z3950-branch/gsdl/src/recpt/pageaction.cpp@ 1168

Last change on this file since 1168 was 1168, checked in by johnmcp, 24 years ago

added proper config file parsing for z39.50 servers, and minor changes
to pageaction (minor bug when display collections from >1 proto) and
cgiwrapper (announces which collections are z39.50 servers).

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