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

Last change on this file since 1535 was 1535, checked in by nzdl, 24 years ago

added new Dutch interface to preferences page

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 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 if (!found_valid_col) {
160 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
161 }
162 homeextra += "</tr></table></center>\n";
163 disp.setmacro ("homeextra", "home", homeextra);
164
165}
166
167void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
168 recptprotolistclass *protos, ostream &logout) {
169
170 // define_internal_macros sets the following macros:
171
172 // _numdocs_ the number of documents in the collection
173
174 // _builddate_ the date last built
175
176
177 // if page is "home"
178 // _homeextra_ this is the list of available collections and collection info
179 // to be displayed on the home page
180
181
182 // if page is "preferences"
183 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
184
185 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
186
187 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
188
189 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
190
191 // _encodingoption_ will be overridden to "" if chinese language interface isn't specified
192
193 // if page is "about"
194 // _textsubcollections_ the text on which subcollections make up the collection (if
195 // cross-collection searching is being used
196
197 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
198
199 // _numbrowseoptions_ the number of browsing options
200
201
202 // if page is "help"
203 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
204
205 // _numbrowseoptions_ the number of browsing options
206
207 // _topicreadingdocs_ this section of the help text differs depending on what type of
208 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
209 // _texthelpreadingdocs_
210
211
212 if (recpt == NULL) {
213 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
214 << " information about any receptionists. The method set_receptionist was\n"
215 << " probably not called from the module which instantiated this action.\n";
216 return;
217 }
218
219 text_t &arg_p = args["p"];
220 text_t &arg_c = args["c"];
221 ColInfoResponse_t *cinfo = NULL;
222
223 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
224 if (collectproto != NULL) {
225 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
226
227 disp.setmacro ("numdocs", "Global", cinfo->numDocs);
228 unsigned long current_time = time(NULL);
229 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
230 disp.setmacro ("builddate", "Global", builddate);
231 }
232
233 if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
234
235 else if (arg_p == "preferences") {
236
237 // _collectionoption_
238
239 if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
240 text_t collectionoption = "_textcollectionoption_";
241 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
242 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
243 int count = 0;
244 while (col_here != col_end) {
245 text_t colname;
246 if (*col_here == arg_c) {
247 colname = cinfo->collectionmeta["collectionname"];
248 } else {
249 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
250 if (this_cinfo == NULL) {col_here ++; continue;}
251 colname = this_cinfo->collectionmeta["collectionname"];
252 }
253
254 count ++;
255 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
256 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
257 colname + "<br>\n";
258 col_here ++;
259 }
260
261 if (count > 1)
262 disp.setmacro ("collectionoption", "preferences", collectionoption);
263 }
264
265 // _htmloptions_
266
267 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
268 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
269 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
270
271
272 // _PreferenceDocsFromWeb_
273
274 it = cinfo->format.find ("PreferenceDocsFromWeb");
275 if ((it == cinfo->format.end()) || ((*it).second == "true"))
276 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
277 }
278
279 // _languageoption_
280 // this is kind of a hack (another one!!). note that there're potential
281 // problems here as no checking is done anywhere to make sure language
282 // is set to a valid value. this does allow us to set which languages
283 // should go in the preference selection box (from collect.cfg) however
284 // and that's sufficient for current requirements
285
286 // currently supported languages (_languageoption_ will default to all
287 // these languages unless PreferenceLanguages is set
288 text_tarray languages;
289 languages.push_back ("en");
290 languages.push_back ("fr");
291 languages.push_back ("de");
292 languages.push_back ("es");
293 languages.push_back ("mi");
294 languages.push_back ("zh");
295 languages.push_back ("ar");
296 languages.push_back ("pt");
297 languages.push_back ("nl");
298 text_tarray::const_iterator this_lang = languages.begin();
299 text_tarray::const_iterator end_lang = languages.end();
300
301 text_t languageoption = "_textlanguage_\n<select name=\"l\" onChange=\"updatel();\">\n";
302 it = cinfo->format.find ("PreferenceLanguages");
303 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
304 text_tset pref_langs;
305 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
306 if (pref_langs.size() > 1) {
307 while (this_lang != end_lang) {
308 if (pref_langs.find(*this_lang) != pref_langs.end())
309 languageoption += "_" + *this_lang + "languageoption_\n";
310 this_lang ++;
311 }
312 languageoption += "</select>\n";
313 disp.setmacro ("languageoption", "preferences", languageoption);
314 }
315
316 // _encodingoption_
317
318 if (pref_langs.find("zh") == pref_langs.end())
319 disp.setmacro ("encodingoption", "preferences", "");
320
321 } else {
322 while (this_lang != end_lang) {
323 languageoption += "_" + *this_lang + "languageoption_\n";
324 this_lang ++;
325 }
326 languageoption += "</select>\n";
327 disp.setmacro ("languageoption", "preferences", languageoption);
328 }
329
330 } else if (arg_p == "about" || arg_p == "help") {
331 if (collectproto == NULL) return;
332
333 // _textbrowseoptions_ and _numbrowseoptions_
334
335 FilterResponse_t response;
336 text_tset metadata;
337 metadata.insert ("Title");
338 bool getParents = false;
339 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
340
341 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
342
343 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
344 ResultDocInfo_tarray::iterator end = response.docInfo.end();
345
346 // we're assuming that we've always got a search button
347 text_t shorttext = "<ul><li>_textSearchshort_\n";
348 text_t longtext = "_textSearchlong_";
349
350 while (here != end) {
351 text_t title = (*here).metadata["Title"].values[0];
352
353 text_t stext, ltext;
354 disp.expandstring ("help", "_text" + title + "short_", stext);
355 if (stext == ("_text" + title + "short_")) {
356 shorttext += "<li>_help:textdefaultshorttext_";
357 longtext += "_help:textdefaultlongtext_";
358 } else {
359 shorttext += "<li>" + stext;
360 longtext += "_help:text" + title + "long_";
361 }
362
363 here ++;
364 }
365 shorttext += "</ul>\n";
366 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
367 else disp.setmacro ("textbrowseoptions", "help", longtext);
368
369 if (arg_p == "help") {
370
371 // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
372
373 // if HTML collection there's no how to read document text
374 text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
375 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
376 disp.setmacro ("topicreadingdocs", "help", "");
377 disp.setmacro ("texthelpreadingdocs", "help", "");
378 }
379 it = cinfo->format.find ("HelpBibDocs");
380 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
381 disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
382 disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
383 }
384 it = cinfo->format.find ("HelpBookDocs");
385 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
386 disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
387 disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
388 }
389
390 }
391 if (arg_p == "about") {
392
393 // _textsubcollections_
394 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
395 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
396 text_tarray::const_iterator here = cinfo->ccsCols.begin();
397 text_tarray::const_iterator end = cinfo->ccsCols.end();
398 bool first = true;
399 int count = 0;
400 while (here != end) {
401 if (*here == arg_c) {
402 if (!first) textsubcollections += "<br>";
403 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
404 } else {
405 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
406 if (this_cinfo == NULL) {here ++; continue;}
407 if (!first) textsubcollections += "<br>";
408 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
409 }
410 count ++;
411 first = false;
412 here ++;
413 }
414 textsubcollections += "_textsubcols2_";
415 if (count > 1)
416 disp.setmacro ("textsubcollections", "about", textsubcollections);
417 }
418 }
419 }
420}
421
422bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
423 browsermapclass * /*browsers*/, displayclass &disp,
424 outconvertclass &outconvert, ostream &textout,
425 ostream &/*logout*/) {
426
427 text_t &arg_p = args["p"];
428
429 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
430 << ("_" + arg_p + ":content_\n")
431 << ("_" + arg_p + ":footer_\n");
432
433 return true;
434}
Note: See TracBrowser for help on using the repository browser.