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

Last change on this file since 928 was 928, checked in by kjm18, 24 years ago

search history stuff added.

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