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

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

more hacky changes to get preferences to be a bit smarter

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