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

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

Removed CVS logging information from source files

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