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

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

re-added the "set preferences" button to the preferences page

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