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

Last change on this file since 1212 was 1212, checked in by sjboddie, 24 years ago

Added French and Spanish language selection options to the preferences
page. I really don't like how this is currently implemented (i.e. you
have to recompile the library to do something so simple), it might have
to wait until the new configuration file stuff is done before it's fixed
though.

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