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

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

Added Portuguese selector to preferences page (actual Portuguese
translation coming soon).

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.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 recpt = NULL;
34
35 // this action uses cgi variables "a", "p", and "hp"
36 cgiarginfo arg_ainfo;
37 arg_ainfo.shortname = "a";
38 arg_ainfo.longname = "action";
39 arg_ainfo.multiplechar = true;
40 arg_ainfo.defaultstatus = cgiarginfo::weak;
41 arg_ainfo.argdefault = "p";
42 arg_ainfo.savedarginfo = cgiarginfo::must;
43 argsinfo.addarginfo (NULL, arg_ainfo);
44
45 arg_ainfo.shortname = "p";
46 arg_ainfo.longname = "page";
47 arg_ainfo.multiplechar = true;
48 arg_ainfo.defaultstatus = cgiarginfo::weak;
49 arg_ainfo.argdefault = "home";
50 arg_ainfo.savedarginfo = cgiarginfo::must;
51 argsinfo.addarginfo (NULL, arg_ainfo);
52
53 arg_ainfo.shortname = "hp";
54 arg_ainfo.longname = "html page";
55 arg_ainfo.multiplechar = true;
56 arg_ainfo.defaultstatus = cgiarginfo::weak;
57 arg_ainfo.argdefault = "";
58 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
59 argsinfo.addarginfo (NULL, arg_ainfo);
60}
61
62pageaction::~pageaction () {
63}
64
65bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
66 ostream &/*logout*/) {
67 // don't want to check anything yet.
68 return true;
69}
70
71void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
72 response_t &response,text_t &response_data,
73 ostream &/*logout*/) {
74 response = content;
75 response_data = "text/html";
76}
77
78void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
79 ostream &logout) {
80
81 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
82 bool found_valid_col = false;
83
84 recptprotolistclass::iterator rprotolist_here = protos->begin();
85 recptprotolistclass::iterator rprotolist_end = protos->end();
86 while (rprotolist_here != rprotolist_end) {
87 if ((*rprotolist_here).p != NULL) {
88
89 text_tarray collist;
90 comerror_t err;
91 (*rprotolist_here).p->get_collection_list (collist, err, logout);
92 if (err == noError) {
93 text_tarray::iterator collist_here = collist.begin();
94 text_tarray::iterator collist_end = collist.end();
95
96 int count = 0;
97 bool first = true;
98 while (collist_here != collist_end) {
99
100 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
101
102 if (cinfo != NULL) {
103 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
104
105 found_valid_col = true;
106 FilterResponse_t response;
107 text_tset metadata;
108 metadata.insert ("collectionname");
109 metadata.insert ("iconcollection");
110 metadata.insert ("iconcollectionsmall");
111 text_t collectionname = *collist_here;
112 text_t alt = collectionname;
113 if (get_info ("collection", *collist_here, metadata, false,
114 (*rprotolist_here).p, response, logout)) {
115 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
116 alt = response.docInfo[0].metadata["collectionname"].values[0];
117
118 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
119 collectionname = "<img width=150 border=1 src=\""
120 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
121 + "\" alt=\"" + alt + "\">";
122 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
123 collectionname = "<img width=150 border=1 src=\""
124 + response.docInfo[0].metadata["iconcollection"].values[0]
125 + "\" alt=\"" + alt + "\">";
126 else collectionname = alt;
127 }
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
148 collist_here ++;
149 }
150
151 // disp.setmacro ("homeextra", "home", homeextra);
152 for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
153 }
154 }
155 homeextra += "</td></tr>\n<tr>\n";
156 rprotolist_here ++;
157 }
158
159 homeextra += "</tr></table></center>\n";
160 disp.setmacro ("homeextra", "home", homeextra);
161
162 if (!found_valid_col) {
163 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
164 }
165 homeextra += "</tr></table></center>\n";
166 disp.setmacro ("homeextra", "home", homeextra);
167
168}
169
170void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
171 recptprotolistclass *protos, ostream &logout) {
172
173 // define_internal_macros sets the following macros:
174
175 // _numdocs_ the number of documents in the collection
176
177 // _builddate_ the date last built
178
179
180 // if page is "home"
181 // _homeextra_ this is the list of available collections and collection info
182 // to be displayed on the home page
183
184
185 // if page is "preferences"
186 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
187
188 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
189
190 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
191
192 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
193
194 // _encodingoption_ will be overridden to "" if chinese language interface isn't specified
195
196 // if page is "about"
197 // _textsubcollections_ the text on which subcollections make up the collection (if
198 // cross-collection searching is being used
199
200 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
201
202 // _numbrowseoptions_ the number of browsing options
203
204
205 // if page is "help"
206 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
207
208 // _numbrowseoptions_ the number of browsing options
209
210 // _topicreadingdocs_ this section of the help text differs depending on what type of
211 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
212 // _texthelpreadingdocs_
213
214
215 if (recpt == NULL) {
216 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
217 << " information about any receptionists. The method set_receptionist was\n"
218 << " probably not called from the module which instantiated this action.\n";
219 return;
220 }
221
222 text_t &arg_p = args["p"];
223 text_t &arg_c = args["c"];
224 ColInfoResponse_t *cinfo = NULL;
225
226 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
227 if (collectproto != NULL) {
228 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
229
230 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
231 unsigned long current_time = time(NULL);
232 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
233 disp.setmacro ("builddate", "Global", builddate);
234 }
235
236 if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
237
238 else if (arg_p == "preferences") {
239
240 // _collectionoption_
241
242 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
243 text_t collectionoption = "_textcollectionoption_";
244 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
245 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
246 int count = 0;
247 while (col_here != col_end) {
248 text_t colname;
249 if (*col_here == arg_c) {
250 colname = cinfo->collectionmeta["collectionname"];
251 } else {
252 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
253 if (this_cinfo == NULL) {col_here ++; continue;}
254 colname = this_cinfo->collectionmeta["collectionname"];
255 }
256
257 count ++;
258 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
259 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
260 colname + "<br>\n";
261 col_here ++;
262 }
263
264 if (count > 1)
265 disp.setmacro ("collectionoption", "preferences", collectionoption);
266 }
267
268 // _htmloptions_
269
270 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
271 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
272 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
273
274
275 // _PreferenceDocsFromWeb_
276
277 it = cinfo->format.find ("PreferenceDocsFromWeb");
278 if ((it == cinfo->format.end()) || ((*it).second == "true"))
279 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
280 }
281
282 // _languageoption_
283 // this is kind of a hack (another one!!). note that there're potential
284 // problems here as no checking is done anywhere to make sure language
285 // is set to a valid value. this does allow us to set which languages
286 // should go in the preference selection box (from collect.cfg) however
287 // and that's sufficient for current requirements
288
289 // currently supported languages (_languageoption_ will default to all
290 // these languages unless PreferenceLanguages is set
291 text_tarray languages;
292 languages.push_back ("en");
293 languages.push_back ("fr");
294 languages.push_back ("de");
295 languages.push_back ("es");
296 languages.push_back ("mi");
297 languages.push_back ("zh");
298 languages.push_back ("ar");
299 languages.push_back ("pt");
300 text_tarray::const_iterator this_lang = languages.begin();
301 text_tarray::const_iterator end_lang = languages.end();
302
303 text_t languageoption = "_textlanguage_\n<select name=\"l\" onChange=\"updatel();\">\n";
304 it = cinfo->format.find ("PreferenceLanguages");
305 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
306 text_tset pref_langs;
307 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
308 if (pref_langs.size() > 1) {
309 while (this_lang != end_lang) {
310 if (pref_langs.find(*this_lang) != pref_langs.end())
311 languageoption += "_" + *this_lang + "languageoption_\n";
312 this_lang ++;
313 }
314 languageoption += "</select>\n";
315 disp.setmacro ("languageoption", "preferences", languageoption);
316 }
317
318 // _encodingoption_
319
320 if (pref_langs.find("zh") == pref_langs.end())
321 disp.setmacro ("encodingoption", "preferences", "");
322
323 } else {
324 while (this_lang != end_lang) {
325 languageoption += "_" + *this_lang + "languageoption_\n";
326 this_lang ++;
327 }
328 languageoption += "</select>\n";
329 disp.setmacro ("languageoption", "preferences", languageoption);
330 }
331
332 } else if (arg_p == "about" || arg_p == "help") {
333 if (collectproto == NULL) return;
334
335 // _textbrowseoptions_ and _numbrowseoptions_
336
337 FilterResponse_t response;
338 text_tset metadata;
339 metadata.insert ("Title");
340 bool getParents = false;
341 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
342
343 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
344
345 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
346 ResultDocInfo_tarray::iterator end = response.docInfo.end();
347
348 // we're assuming that we've always got a search button
349 text_t shorttext = "<ul><li>_textSearchshort_\n";
350 text_t longtext = "_textSearchlong_";
351
352 while (here != end) {
353 text_t title = (*here).metadata["Title"].values[0];
354
355 text_t stext, ltext;
356 disp.expandstring ("help", "_text" + title + "short_", stext);
357 if (stext == ("_text" + title + "short_")) {
358 shorttext += "<li>_help:textdefaultshorttext_";
359 longtext += "_help:textdefaultlongtext_";
360 } else {
361 shorttext += "<li>" + stext;
362 longtext += "_help:text" + title + "long_";
363 }
364
365 here ++;
366 }
367 shorttext += "</ul>\n";
368 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
369 else disp.setmacro ("textbrowseoptions", "help", longtext);
370
371 if (arg_p == "help") {
372
373 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
374
375 // if HTML collection there's no how to read document text
376 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
377 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
378 disp.setmacro ("topicreadingdocs", "help", "");
379 disp.setmacro ("texthelpreadingdocs", "help", "");
380 }
381 it = cinfo->format.find ("HelpBibDocs");
382 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
383 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
384 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
385 }
386 it = cinfo->format.find ("HelpBookDocs");
387 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
388 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
389 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
390 }
391
392 }
393 if (arg_p == "about") {
394
395 // _textsubcollections_
396 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
397 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
398 text_tarray::const_iterator here = cinfo->ccsCols.begin();
399 text_tarray::const_iterator end = cinfo->ccsCols.end();
400 bool first = true;
401 int count = 0;
402 while (here != end) {
403 if (*here == arg_c) {
404 if (!first) textsubcollections += "<br>";
405 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
406 } else {
407 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
408 if (this_cinfo == NULL) {here ++; continue;}
409 if (!first) textsubcollections += "<br>";
410 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
411 }
412 count ++;
413 first = false;
414 here ++;
415 }
416 textsubcollections += "_textsubcols2_";
417 if (count > 1)
418 disp.setmacro ("textsubcollections", "about", textsubcollections);
419 }
420 }
421 }
422}
423
424bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
425 browsermapclass * /*browsers*/, displayclass &disp,
426 outconvertclass &outconvert, ostream &textout,
427 ostream &/*logout*/) {
428
429 text_t &arg_p = args["p"];
430
431 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
432 << ("_" + arg_p + ":content_\n")
433 << ("_" + arg_p + ":footer_\n");
434
435 return true;
436}
Note: See TracBrowser for help on using the repository browser.