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

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

fixed up messy hack for meldex

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