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

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

added german language interface

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