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

Last change on this file since 1912 was 1912, checked in by kjm18, 23 years ago

new cgiarg added to collection urls on home page: &ct=0 for mg cols, &ct=1 for
mgpp cols. determined by cinfo->buildType which =mgpp for mgpp cols

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