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

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

Added Arabic language and encoding options to the preferences page. This
is a much more complex task than it should be (you even have to recompile!)
but it's not really worth fixing until the new config file format is
finalised.

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