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

Last change on this file since 1856 was 1856, checked in by sjboddie, 23 years ago

Added Encoding and Language options to main.cfg configuration file so
it's now hopefully a little easier to add new languages and encodings
to the interface. Each interface language also now has a default encoding
so that changing languages from the preferences page causes the encoding
to change to a value reasonable for the selected language.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.2 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 *********************************************************************/
25
26#include "OIDtools.h"
27#include "pageaction.h"
28#include "receptionist.h"
29#include <time.h>
30
31pageaction::pageaction () {
32
33 status_disabled = true;
34 collector_disabled = true;
35 recpt = NULL;
36
37 // this action uses cgi variables "a", "p", and "hp"
38 cgiarginfo arg_ainfo;
39 arg_ainfo.shortname = "a";
40 arg_ainfo.longname = "action";
41 arg_ainfo.multiplechar = true;
42 arg_ainfo.defaultstatus = cgiarginfo::weak;
43 arg_ainfo.argdefault = "p";
44 arg_ainfo.savedarginfo = cgiarginfo::must;
45 argsinfo.addarginfo (NULL, arg_ainfo);
46
47 arg_ainfo.shortname = "p";
48 arg_ainfo.longname = "page";
49 arg_ainfo.multiplechar = true;
50 arg_ainfo.defaultstatus = cgiarginfo::weak;
51 arg_ainfo.argdefault = "home";
52 arg_ainfo.savedarginfo = cgiarginfo::must;
53 argsinfo.addarginfo (NULL, arg_ainfo);
54
55 arg_ainfo.shortname = "hp";
56 arg_ainfo.longname = "html page";
57 arg_ainfo.multiplechar = true;
58 arg_ainfo.defaultstatus = cgiarginfo::weak;
59 arg_ainfo.argdefault = "";
60 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
61 argsinfo.addarginfo (NULL, arg_ainfo);
62}
63
64pageaction::~pageaction () {
65}
66
67bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
68 ostream &/*logout*/) {
69 // don't want to check anything yet.
70 return true;
71}
72
73void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
74 response_t &response,text_t &response_data,
75 ostream &/*logout*/) {
76 response = content;
77 response_data = "text/html";
78}
79
80void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
81 ostream &logout) {
82
83 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
84 bool found_valid_col = false;
85
86 recptprotolistclass::iterator rprotolist_here = protos->begin();
87 recptprotolistclass::iterator rprotolist_end = protos->end();
88 while (rprotolist_here != rprotolist_end) {
89 if ((*rprotolist_here).p != NULL) {
90
91 text_tarray collist;
92 comerror_t err;
93 (*rprotolist_here).p->get_collection_list (collist, err, logout);
94 if (err == noError) {
95 text_tarray::iterator collist_here = collist.begin();
96 text_tarray::iterator collist_end = collist.end();
97
98 int count = 0;
99 bool first = true;
100 while (collist_here != collist_end) {
101 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
102
103 if (cinfo != NULL) {
104 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
105
106 found_valid_col = true;
107 FilterResponse_t response;
108 text_tset metadata;
109 metadata.insert ("collectionname");
110 metadata.insert ("iconcollection");
111 metadata.insert ("iconcollectionsmall");
112 text_t collectionname = *collist_here;
113 text_t alt = collectionname;
114 if (get_info ("collection", *collist_here, metadata, false,
115 (*rprotolist_here).p, response, logout)) {
116 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
117 alt = response.docInfo[0].metadata["collectionname"].values[0];
118
119 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
120 collectionname = "<img width=150 border=1 src=\""
121 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
122 + "\" alt=\"" + alt + "\">";
123 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
124 collectionname = "<img width=150 border=1 src=\""
125 + response.docInfo[0].metadata["iconcollection"].values[0]
126 + "\" alt=\"" + alt + "\">";
127 else collectionname = alt;
128 }
129 if ((count%3 == 0) && (!first))
130 homeextra += "</tr><tr valign=top>\n";
131
132 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
133 if (*collist_here == "chinese")
134 link = "<a href=\"_gwcgi_?a=p&p=about&l=zh&nw=u&c=" + *collist_here + "\">";
135 if (*collist_here == "arabic")
136 link = "<a href=\"_gwcgi_?a=p&p=about&l=ar&nw=u&c=" + *collist_here + "\">";
137
138 if (!cinfo->receptionist.empty())
139 link = "<a href=\"" + cinfo->receptionist + "\">";
140
141 homeextra += "<td>" + link + collectionname + "</a></td>\n";
142
143 count ++;
144 first = false;
145 }
146 }
147 collist_here ++;
148 }
149
150 // disp.setmacro ("homeextra", "home", homeextra);
151 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
152 }
153 }
154 homeextra += "</td></tr>\n<tr>\n";
155 rprotolist_here ++;
156 }
157
158 if (!found_valid_col) {
159 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
160 }
161 homeextra += "</tr></table></center>\n";
162 disp.setmacro ("homeextra", "home", homeextra);
163}
164
165void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
166 recptprotolistclass *protos, ostream &logout) {
167
168 // define_internal_macros sets the following macros:
169
170 // _numdocs_ the number of documents in the collection
171
172 // _builddate_ the date last built
173
174
175 // if page is "home"
176 // _homeextra_ this is the list of available collections and collection info
177 // to be displayed on the home page
178
179
180 // if page is "preferences"
181 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
182
183 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
184
185 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
186
187 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
188
189 // _encodingoption_ encodings to select from
190
191 // if page is "about"
192 // _textsubcollections_ the text on which subcollections make up the collection (if
193 // cross-collection searching is being used
194
195 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
196
197 // _numbrowseoptions_ the number of browsing options
198
199
200 // if page is "help"
201 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
202
203 // _numbrowseoptions_ the number of browsing options
204
205 // _topicreadingdocs_ this section of the help text differs depending on what type of
206 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
207 // _texthelpreadingdocs_
208
209 // _textgocollector_ set to "" if collector is disabled in main.cfg
210 // _textgoadmin_ set to "" if status is disabled in main.cfg
211
212
213 if (recpt == NULL) {
214 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
215 << " information about any receptionists. The method set_receptionist was\n"
216 << " probably not called from the module which instantiated this action.\n";
217 return;
218 }
219
220 text_t &arg_p = args["p"];
221 text_t &arg_c = args["c"];
222 ColInfoResponse_t *cinfo = NULL;
223
224 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
225 if (collectproto != NULL) {
226 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
227
228 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
229 unsigned long current_time = time(NULL);
230 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
231 disp.setmacro ("builddate", "Global", builddate);
232 }
233
234 if (arg_p == "home") {
235 set_homeextra_macro (disp, protos, logout);
236 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
237 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
238 }
239
240 else if (arg_p == "preferences") {
241
242 // _collectionoption_
243
244 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
245 text_t collectionoption = "_textcollectionoption_";
246 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
247 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
248 int count = 0;
249 while (col_here != col_end) {
250 text_t colname;
251 if (*col_here == arg_c) {
252 colname = cinfo->collectionmeta["collectionname"];
253 } else {
254 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
255 if (this_cinfo == NULL) {col_here ++; continue;}
256 colname = this_cinfo->collectionmeta["collectionname"];
257 }
258
259 count ++;
260 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
261 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
262 colname + "<br>\n";
263 col_here ++;
264 }
265
266 if (count > 1)
267 disp.setmacro ("collectionoption", "preferences", collectionoption);
268 }
269
270 // _htmloptions_
271
272 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
273 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
274 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
275
276
277 // _PreferenceDocsFromWeb_
278
279 it = cinfo->format.find ("PreferenceDocsFromWeb");
280 if ((it == cinfo->format.end()) || ((*it).second == "true"))
281 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
282 }
283
284 // _languageoption_
285 // Create the "interface language" selection box for the preferences page.
286 // You can use something like "format PreferenceLanguages en|fr|zn" from within
287 // a collect.cfg file to use only a subset of the available languages for
288 // any given collection. This facility is kind of ugly though and should be
289 // replaced by something better when the configuration files are tidied up (as
290 // should all the other "format Preference..." options).
291
292 text_t &arg_l = args["l"];
293 const recptconf &configinfo = recpt->get_configinfo();
294 // put languages in another map to sort them by longname
295 text_tmap languages;
296 languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
297 languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
298 while (thislang != endlang) {
299 languages[(*thislang).second.longname] = (*thislang).first;
300 thislang++;
301 }
302 text_tmap::iterator tlang = languages.begin();
303 text_tmap::iterator elang = languages.end();
304
305 text_t languageoption;
306 it = cinfo->format.find ("PreferenceLanguages");
307 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
308 text_tset pref_langs;
309 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
310 if (pref_langs.size() > 1) {
311 while (tlang != elang) {
312 if (pref_langs.find((*tlang).second) != pref_langs.end()) {
313 languageoption += "<option value=\"" + (*tlang).second + "\"";
314 if ((*tlang).second == arg_l) languageoption += " selected";
315 languageoption += ">" + (*tlang).first + "\n";
316 }
317 tlang ++;
318 }
319 }
320
321 } else {
322 while (tlang != elang) {
323 languageoption += "<option value=\"" + (*tlang).second + "\"";
324 if ((*tlang).second == arg_l) languageoption += " selected";
325 languageoption += ">" + (*tlang).first + "\n";
326 tlang ++;
327 }
328 }
329 if (!languageoption.empty()) {
330 languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
331 languageoption += "</select>\n";
332 disp.setmacro ("languageoption", "preferences", languageoption);
333 }
334
335 // _encodingoption_
336 // create the "encoding" selection box for the preferences page
337 text_t &arg_w = args["w"];
338 // put encodings in another map to sort them by longname
339 text_tmap encodings;
340 encodinginfo_tmap::const_iterator thisenc = configinfo.encodings.begin();
341 encodinginfo_tmap::const_iterator endenc = configinfo.encodings.end();
342 while (thisenc != endenc) {
343 encodings[(*thisenc).second.longname] = (*thisenc).first;
344 thisenc++;
345 }
346 text_tmap::iterator tenc = encodings.begin();
347 text_tmap::iterator eenc = encodings.end();
348
349 text_t encodingoption;
350 while (tenc != eenc) {
351 encodingoption += "<option value=\"" + (*tenc).second + "\"";
352 if ((*tenc).second == arg_w) encodingoption += " selected";
353 encodingoption += ">" + (*tenc).first + "\n";
354 tenc ++;
355 }
356
357 if (!encodingoption.empty()) {
358 encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
359 encodingoption += "</select>\n";
360 disp.setmacro ("encodingoption", "preferences", encodingoption);
361 }
362
363 } else if (arg_p == "about" || arg_p == "help") {
364 if (collectproto == NULL) return;
365
366 // _textbrowseoptions_ and _numbrowseoptions_
367
368 FilterResponse_t response;
369 text_tset metadata;
370 metadata.insert ("Title");
371 bool getParents = false;
372 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
373
374 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
375
376 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
377 ResultDocInfo_tarray::iterator end = response.docInfo.end();
378
379 // we're assuming that we've always got a search button
380 text_t shorttext = "<ul><li>_textSearchshort_\n";
381 text_t longtext = "_textSearchlong_";
382
383 while (here != end) {
384 text_t title = (*here).metadata["Title"].values[0];
385
386 text_t stext, ltext;
387 disp.expandstring ("help", "_text" + title + "short_", stext);
388 if (stext == ("_text" + title + "short_")) {
389 shorttext += "<li>_help:textdefaultshorttext_";
390 longtext += "_help:textdefaultlongtext_";
391 } else {
392 shorttext += "<li>_help:text" + title + "short_";
393 longtext += "_help:text" + title + "long_";
394 }
395
396 here ++;
397 }
398 shorttext += "</ul>\n";
399 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
400 else disp.setmacro ("textbrowseoptions", "help", longtext);
401
402 if (arg_p == "help") {
403
404 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
405
406 // if HTML collection there's no how to read document text
407 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
408 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
409 disp.setmacro ("topicreadingdocs", "help", "");
410 disp.setmacro ("texthelpreadingdocs", "help", "");
411 }
412 it = cinfo->format.find ("HelpBibDocs");
413 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
414 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
415 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
416 }
417 it = cinfo->format.find ("HelpBookDocs");
418 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
419 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
420 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
421 }
422
423 }
424 if (arg_p == "about") {
425
426 // _textsubcollections_
427 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
428 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
429 text_tarray::const_iterator here = cinfo->ccsCols.begin();
430 text_tarray::const_iterator end = cinfo->ccsCols.end();
431 bool first = true;
432 int count = 0;
433 while (here != end) {
434 if (*here == arg_c) {
435 if (!first) textsubcollections += "<br>";
436 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
437 } else {
438 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
439 if (this_cinfo == NULL) {here ++; continue;}
440 if (!first) textsubcollections += "<br>";
441 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
442 }
443 count ++;
444 first = false;
445 here ++;
446 }
447 textsubcollections += "_textsubcols2_";
448 if (count > 1)
449 disp.setmacro ("textsubcollections", "about", textsubcollections);
450 }
451 }
452 }
453}
454
455bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
456 browsermapclass * /*browsers*/, displayclass &disp,
457 outconvertclass &outconvert, ostream &textout,
458 ostream &/*logout*/) {
459
460 text_t &arg_p = args["p"];
461
462 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
463 << ("_" + arg_p + ":content_\n")
464 << ("_" + arg_p + ":footer_\n");
465
466 return true;
467}
468
469void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
470 if ((key == "status") && (cfgline.size() == 1) &&
471 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
472 status_disabled = false;
473 } else if ((key == "collector") && (cfgline.size() == 1) &&
474 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
475 collector_disabled = false;
476 } else {
477 // call the parent class to deal with the things which
478 // are not dealt with here
479 action::configure (key, cfgline);
480 }
481}
Note: See TracBrowser for help on using the repository browser.