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

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

Tidied up the way collections are displayed on 'standard' homepage.
Removed all the nzdl.org specific stuff.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 18.4 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 1247 2000-06-27 23:02:40Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.32 2000/06/27 23:02:40 sjboddie
31 Tidied up the way collections are displayed on 'standard' homepage.
32 Removed all the nzdl.org specific stuff.
33
34 Revision 1.31 2000/06/23 03:48:08 sjboddie
35 Added Arabic language and encoding options to the preferences page. This
36 is a much more complex task than it should be (you even have to recompile!)
37 but it's not really worth fixing until the new config file format is
38 finalised.
39
40 Revision 1.30 2000/06/14 22:33:42 sjboddie
41 Added French and Spanish language selection options to the preferences
42 page. I really don't like how this is currently implemented (i.e. you
43 have to recompile the library to do something so simple), it might have
44 to wait until the new configuration file stuff is done before it's fixed
45 though.
46
47 Revision 1.29 2000/03/19 21:16:46 nzdl
48 added german language interface
49
50 Revision 1.28 2000/02/24 01:19:01 sjboddie
51 fixed up messy hack for meldex
52
53 Revision 1.27 2000/02/15 22:53:51 kjm18
54 search history stuff added.
55
56 Revision 1.26 2000/02/03 01:49:35 sjboddie
57 fixed up some of the preferences stuff
58
59 Revision 1.25 2000/01/26 20:11:04 sjboddie
60 added some collection specific help text
61
62 Revision 1.24 2000/01/25 22:31:09 sjboddie
63 more hacky changes to get preferences to be a bit smarter
64
65 Revision 1.23 2000/01/24 22:59:57 sjboddie
66 changes to set macros differently for preferences page depending
67 on type of collection - pageaction is getting kind of hacky - should
68 tidy it up some day
69
70 Revision 1.22 1999/11/25 23:01:09 sjboddie
71 now need to be able to handle it if no collection is selected
72
73 Revision 1.21 1999/11/03 22:50:13 sjboddie
74 now defaults to home page
75
76 Revision 1.20 1999/11/01 21:58:02 sjboddie
77 changes to arguments of many functions, now pass list of protocols
78 instead of just that for this collection
79
80 Revision 1.19 1999/10/19 21:59:09 sjboddie
81 bug in generating "how to find information" text for about pages
82
83 Revision 1.18 1999/10/19 03:23:44 davidb
84 Collection building support through web pages
85 and internal and external link handling for collection documents
86
87 Revision 1.17 1999/10/14 23:04:44 sjboddie
88 some hacks to make nzdl home page look right
89
90 Revision 1.16 1999/10/10 08:14:09 sjboddie
91 - metadata now returns mp rather than array
92 - redesigned browsing support (although it's not finished so
93 won't currently work ;-)
94
95 Revision 1.15 1999/09/17 04:46:05 sjboddie
96 fixed a couple of problems with 'unknown' classifier
97
98 Revision 1.14 1999/09/07 23:08:09 rjmcnab
99 Removed some compiler warnings
100
101 Revision 1.13 1999/09/07 04:56:57 sjboddie
102 added GPL notice
103
104 Revision 1.12 1999/09/02 00:26:43 rjmcnab
105 made the p cgi argument always saved in the compressed arguments
106
107 Revision 1.11 1999/08/25 04:48:43 sjboddie
108 changes to the home and about pages
109
110 Revision 1.10 1999/08/11 23:29:43 sjboddie
111 added support for html classifier (i.e. the hp argument)
112
113 Revision 1.9 1999/08/03 03:29:47 sjboddie
114 added ability to set receptionist from collect.cfg
115
116 Revision 1.8 1999/07/30 02:24:44 sjboddie
117 added collectinfo argument to some functions
118
119 Revision 1.7 1999/06/24 05:12:24 sjboddie
120 lots of small changes
121
122 Revision 1.6 1999/06/10 00:39:16 sjboddie
123 navigation bar is no longer written out for every page (it should
124 be included in the _content_ macro of pages wanting to display it).
125
126 Revision 1.5 1999/06/08 04:29:35 sjboddie
127 added argsinfo to the call to check_cgiargs to make it easy to set
128 args to their default if they're found to be screwed up
129
130 Revision 1.4 1999/02/28 20:00:14 rjmcnab
131
132
133 Fixed a few things.
134
135 Revision 1.3 1999/02/25 21:58:58 rjmcnab
136
137 Merged sources.
138
139 Revision 1.2 1999/02/21 22:33:54 rjmcnab
140
141 Lots of stuff :-)
142
143 Revision 1.1 1999/02/12 02:40:17 sjboddie
144
145 Added page action
146
147 */
148
149#include "OIDtools.h"
150#include "pageaction.h"
151#include "receptionist.h"
152#include <time.h>
153
154pageaction::pageaction () {
155
156 recpt = NULL;
157
158 // this action uses cgi variables "a", "p", and "hp"
159 cgiarginfo arg_ainfo;
160 arg_ainfo.shortname = "a";
161 arg_ainfo.longname = "action";
162 arg_ainfo.multiplechar = true;
163 arg_ainfo.defaultstatus = cgiarginfo::weak;
164 arg_ainfo.argdefault = "p";
165 arg_ainfo.savedarginfo = cgiarginfo::must;
166 argsinfo.addarginfo (NULL, arg_ainfo);
167
168 arg_ainfo.shortname = "p";
169 arg_ainfo.longname = "page";
170 arg_ainfo.multiplechar = true;
171 arg_ainfo.defaultstatus = cgiarginfo::weak;
172 arg_ainfo.argdefault = "home";
173 arg_ainfo.savedarginfo = cgiarginfo::must;
174 argsinfo.addarginfo (NULL, arg_ainfo);
175
176 arg_ainfo.shortname = "hp";
177 arg_ainfo.longname = "html page";
178 arg_ainfo.multiplechar = true;
179 arg_ainfo.defaultstatus = cgiarginfo::weak;
180 arg_ainfo.argdefault = "";
181 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
182 argsinfo.addarginfo (NULL, arg_ainfo);
183}
184
185pageaction::~pageaction () {
186}
187
188bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
189 ostream &/*logout*/) {
190 // don't want to check anything yet.
191 return true;
192}
193
194void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
195 response_t &response,text_t &response_data,
196 ostream &/*logout*/) {
197 response = content;
198 response_data = "text/html";
199}
200
201void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
202 ostream &logout) {
203
204 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
205
206 recptprotolistclass::iterator rprotolist_here = protos->begin();
207 recptprotolistclass::iterator rprotolist_end = protos->end();
208 while (rprotolist_here != rprotolist_end) {
209 if ((*rprotolist_here).p != NULL) {
210
211 text_tarray collist;
212 comerror_t err;
213 (*rprotolist_here).p->get_collection_list (collist, err, logout);
214 if (err == noError) {
215 text_tarray::iterator collist_here = collist.begin();
216 text_tarray::iterator collist_end = collist.end();
217
218 int count = 0;
219 bool first = true;
220 while (collist_here != collist_end) {
221
222 ColInfoResponse_t cinfo;
223 (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout);
224
225 if (err == noError) {
226 if (cinfo.isPublic && (cinfo.buildDate > 0)) {
227
228 FilterResponse_t response;
229 text_tset metadata;
230 metadata.insert ("collectionname");
231 metadata.insert ("iconcollection");
232 metadata.insert ("iconcollectionsmall");
233 text_t collectionname = *collist_here;
234 text_t alt = collectionname;
235 if (get_info ("collection", *collist_here, metadata, false,
236 (*rprotolist_here).p, response, logout)) {
237 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
238 alt = response.docInfo[0].metadata["collectionname"].values[0];
239
240 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
241 collectionname = "<img width=150 border=1 src=\""
242 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
243 + "\" alt=\"" + alt + "\">";
244 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
245 collectionname = "<img width=150 border=1 src=\""
246 + response.docInfo[0].metadata["iconcollection"].values[0]
247 + "\" alt=\"" + alt + "\">";
248 else collectionname = alt;
249 }
250
251 if ((count%3 == 0) && (!first))
252 homeextra += "</tr><tr valign=top>\n";
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&l=ar&nw=u&c=" + *collist_here + "\">";
259
260 if (!cinfo.receptionist.empty())
261 link = "<a href=\"" + cinfo.receptionist + "\">";
262
263 homeextra += "<td>" + link + collectionname + "</a></td>\n";
264
265 count ++;
266 first = false;
267 }
268 }
269
270 collist_here ++;
271 }
272 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
273 homeextra += "</tr></table></center>\n";
274 disp.setmacro ("homeextra", "home", homeextra);
275 }
276 }
277 rprotolist_here ++;
278 }
279}
280
281void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
282 recptprotolistclass *protos, ostream &logout) {
283
284 // define_internal_macros sets the following macros:
285
286 // _numdocs_ the number of documents in the collection
287
288 // _builddate_ the date last built
289
290
291 // if page is "home"
292 // _homeextra_ this is the list of available collections and collection info
293 // to be displayed on the home page
294
295
296 // if page is "preferences"
297 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
298
299 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
300
301 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
302
303 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
304
305 // _encodingoption_ will be overridden to "" if chinese language interface isn't specified
306
307 // if page is "about"
308 // _textsubcollections_ the text on which subcollections make up the collection (if
309 // cross-collection searching is being used
310
311 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
312
313 // _numbrowseoptions_ the number of browsing options
314
315
316 // if page is "help"
317 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
318
319 // _numbrowseoptions_ the number of browsing options
320
321 // _topicreadingdocs_ this section of the help text differs depending on what type of
322 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
323 // _texthelpreadingdocs_
324
325
326 text_t &arg_p = args["p"];
327 text_t &arg_c = args["c"];
328 ColInfoResponse_t cinfo;
329 comerror_t err;
330
331 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
332 if (collectproto != NULL) {
333 collectproto->get_collectinfo (arg_c, cinfo, err, logout);
334
335 disp.setmacro ("numdocs", "Global", cinfo.numDocs);
336 unsigned long current_time = time(NULL);
337 unsigned long builddate = (current_time - cinfo.buildDate) / 86400;
338 disp.setmacro ("builddate", "Global", builddate);
339 }
340
341 if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
342
343 else if (arg_p == "preferences") {
344
345 // _collectionoption_
346
347 if (args["ccs"] == "1" && collectproto != NULL && (cinfo.ccsCols.size() > 1)) {
348 text_t collectionoption = "_textcollectionoption_";
349 text_tarray::const_iterator col_here = cinfo.ccsCols.begin();
350 text_tarray::const_iterator col_end = cinfo.ccsCols.end();
351 int count = 0;
352 while (col_here != col_end) {
353 text_t colname;
354 if (*col_here == arg_c) {
355 colname = cinfo.collectionmeta["collectionname"];
356 } else {
357 ColInfoResponse_t this_cinfo;
358 collectproto->get_collectinfo (*col_here, this_cinfo, err, logout);
359 if (err != noError) {col_here ++; continue;}
360 colname = this_cinfo.collectionmeta["collectionname"];
361 }
362
363 count ++;
364 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
365 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
366 colname + "<br>\n";
367 col_here ++;
368 }
369
370 if (count > 1)
371 disp.setmacro ("collectionoption", "preferences", collectionoption);
372 }
373
374 // _htmloptions_
375
376 text_tmap::const_iterator it = cinfo.format.find ("DocumentUseHTML");
377 if ((it != cinfo.format.end()) && ((*it).second == "true")) {
378 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
379
380
381 // _PreferenceDocsFromWeb_
382
383 it = cinfo.format.find ("PreferenceDocsFromWeb");
384 if ((it == cinfo.format.end()) || ((*it).second == "true"))
385 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
386 }
387
388 // _languageoption_
389 // this is kind of a hack (another one!!). note that there're potential
390 // problems here as no checking is done anywhere to make sure language
391 // is set to a valid value. this does allow us to set which languages
392 // should go in the preference selection box (from collect.cfg) however
393 // and that's sufficient for current requirements
394
395 // currently supported languages (_languageoption_ will default to all
396 // these languages unless PreferenceLanguages is set
397 text_tarray languages;
398 languages.push_back ("en");
399 languages.push_back ("fr");
400 languages.push_back ("de");
401 languages.push_back ("es");
402 languages.push_back ("mi");
403 languages.push_back ("zh");
404 languages.push_back ("ar");
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.