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

Last change on this file since 7441 was 7441, checked in by mdewsnip, 20 years ago

(Human Info) Replace all "" with g_EmptyText.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 34.4 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// Changelog:
27
28// 11th July 2003:
29
30// Added 3 functions to deal with the collection style
31// A deciding function and then 2 functions that actually
32// do the work for us, either images or pulldown.
33
34
35#include "OIDtools.h"
36#include "pageaction.h"
37#include "receptionist.h"
38#include "fileutil.h"
39#include "gsdltools.h"
40#include <time.h>
41
42pageaction::pageaction () {
43
44 status_disabled = true;
45 collector_disabled = true;
46 translator_disabled = true;
47 recpt = NULL;
48
49 // this action uses cgi variables "a", "p", and "hp"
50 cgiarginfo arg_ainfo;
51 arg_ainfo.shortname = "a";
52 arg_ainfo.longname = "action";
53 arg_ainfo.multiplechar = true;
54 arg_ainfo.defaultstatus = cgiarginfo::weak;
55 arg_ainfo.argdefault = "p";
56 arg_ainfo.savedarginfo = cgiarginfo::must;
57 argsinfo.addarginfo (NULL, arg_ainfo);
58
59 arg_ainfo.shortname = "p";
60 arg_ainfo.longname = "page";
61 arg_ainfo.multiplechar = true;
62 arg_ainfo.defaultstatus = cgiarginfo::weak;
63 arg_ainfo.argdefault = "home";
64 arg_ainfo.savedarginfo = cgiarginfo::must;
65 argsinfo.addarginfo (NULL, arg_ainfo);
66
67 arg_ainfo.shortname = "hp";
68 arg_ainfo.longname = "html page";
69 arg_ainfo.multiplechar = true;
70 arg_ainfo.defaultstatus = cgiarginfo::weak;
71 arg_ainfo.argdefault = g_EmptyText;
72 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
73 argsinfo.addarginfo (NULL, arg_ainfo);
74
75 arg_ainfo.shortname = "bp";
76 arg_ainfo.longname = "set preferences button";
77 arg_ainfo.multiplechar = true;
78 arg_ainfo.defaultstatus = cgiarginfo::weak;
79 arg_ainfo.argdefault = g_EmptyText;
80 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
81 argsinfo.addarginfo (NULL, arg_ainfo);
82
83 // the "u" argument will disable the search facility, remove links to the
84 // home and preferences pages, and disable the DocumentButton buttons
85 // (for use when generating static html versions of collections)
86 arg_ainfo.shortname = "u";
87 arg_ainfo.longname = "static page";
88 arg_ainfo.multiplechar = false;
89 arg_ainfo.defaultstatus = cgiarginfo::weak;
90 arg_ainfo.argdefault = "0";
91 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
92 argsinfo.addarginfo (NULL, arg_ainfo);
93}
94
95pageaction::~pageaction () {
96}
97
98bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args,
99 recptprotolistclass * /*protos*/, ostream &/*logout*/) {
100
101 if (args["p"] == "preferences" && !args["bp"].empty()) {
102 if (args["hd"] != "0") args["hd"] = args["hdn"];
103 }
104
105 return true;
106}
107
108void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
109 response_t &response,text_t &response_data,
110 ostream &/*logout*/) {
111 response = content;
112 response_data = "text/html";
113}
114
115// This function helps decide whether we want a
116// images or pulldown style collection display
117// We refer to the macro files for the options
118// for images or pulldown menu and use that to
119// switch to the appropriate function to do the job
120
121// Aly Dharshi
122// 11th July 2003
123
124void pageaction::homepagestyle(displayclass &disp, recptprotolistclass *protos,
125 cgiargsclass &args, ostream &logout)
126{
127
128 const recptconf &configinfo = recpt->get_configinfo();
129
130 if (configinfo.HomePageType == "images") {
131 home_images(disp, protos, args, configinfo, logout);
132
133 } else
134 {
135 home_pulldown(disp, protos, args, configinfo, logout);
136 }
137}
138
139// This function allows for the Greenstone
140// collection to be displayed in a pull down
141// menu similar to that in documentaction.cpp
142
143// Aly Dharshi
144// 11th July 2003
145
146void pageaction::home_pulldown(displayclass &disp, recptprotolistclass *protos,
147 cgiargsclass &args, const recptconf &configinfo,
148 ostream &logout) {
149
150 //text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
151 //bool found_valid_col = false;
152
153 text_t homeextra = "<form method=\"get\" name=\"browse\">\n";
154 homeextra += "<select name=\"collections\" onChange=\"location.href=";
155 homeextra += "document.browse.collections.options[document.browse.collections.selectedIndex].value\">\n";
156
157
158 recptprotolistclass::iterator rprotolist_here = protos->begin();
159 recptprotolistclass::iterator rprotolist_end = protos->end();
160 while (rprotolist_here != rprotolist_end) {
161 if ((*rprotolist_here).p != NULL) {
162
163 text_tarray collist;
164 comerror_t err;
165 (*rprotolist_here).p->get_collection_list (collist, err, logout);
166 if (err == noError) {
167 text_tarray::iterator collist_here = collist.begin();
168 text_tarray::iterator collist_end = collist.end();
169
170 int count = 0;
171 bool first = true;
172 while (collist_here != collist_end) {
173 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
174
175 if (cinfo != NULL) {
176 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
177
178 text_t coll_type = "&ct=";
179 if (cinfo->buildType == "mgpp") {
180 coll_type += "1&qto=";
181
182 // now we also want to check search types to set the qto arg
183 if (cinfo->searchTypes.size() == 0) {
184 coll_type += "3"; // default to 3 (= both)
185 } else {
186 unsigned int search_types = 0;
187 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
188 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
189
190 while (type_here != type_end) {
191 if (*type_here == "form") {
192 search_types |= 2;
193 } else if (*type_here == "plain") {
194 search_types |= 1;
195 }
196 type_here ++;
197 }
198 coll_type += search_types;
199 if (search_types == 3) {
200 // both were specified, now need to look at the order to see which is the default
201 type_here = cinfo->searchTypes.begin();
202 if (*type_here == "form") {
203 coll_type += "&qt=1"; // set the default to form
204 }
205 }
206
207 }
208 }
209 else {
210 coll_type += "0";
211 }
212
213 FilterResponse_t response;
214 text_tset metadata;
215 metadata.insert ("collectionname");
216 text_t lang = args["l"];
217 if (!lang.empty()) {
218 metadata.insert ("collectionname:"+lang);
219 }
220 text_t collectionname = *collist_here;
221
222 if (get_info ("collection", *collist_here, "", metadata, false,
223 (*rprotolist_here).p, response, logout)) {
224 if (!lang.empty() && !response.docInfo[0].metadata["collectionname:"+lang].values[0].empty()) {
225 collectionname = response.docInfo[0].metadata["collectionname:"+lang].values[0];
226 } else if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
227 collectionname = response.docInfo[0].metadata["collectionname"].values[0];
228 }
229 }
230
231 comerror_t err;
232 text_t optsite = g_EmptyText;
233 text_t site_name = (*rprotolist_here).p->get_site_name (err);
234 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
235
236 text_t link = "_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type;
237 link += "&l=" + args["l"] + "&w=" + args["w"];
238
239 // We are "dynamically" overriding so to speak the
240 // link to the collection aka receptionist.
241
242 if (!cinfo->receptionist.empty())
243 link = cinfo->receptionist;
244
245
246 homeextra += "<option value=\"" + link + "\"";
247 homeextra += ">" + collectionname + "</option>\n";
248
249 }
250
251 collist_here ++;
252 }
253
254 }
255 }
256 rprotolist_here ++;
257 }
258
259 }
260 homeextra += "</select>\n";
261 homeextra += "</form>\n";
262
263 disp.setmacro ("homeextra", "home", homeextra);
264}
265
266// originally called set_homeextra_macro
267// this function displays the Greenstone
268// main page as usual with the graphics for
269// the collections.
270
271// Aly Dharshi
272// 11th July 2003
273
274void pageaction::home_images(displayclass &disp, recptprotolistclass *protos,
275 cgiargsclass &args, const recptconf &configinfo,
276 ostream &logout) {
277
278 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
279 bool found_valid_col = false;
280 recptprotolistclass::iterator rprotolist_here = protos->begin();
281 recptprotolistclass::iterator rprotolist_end = protos->end();
282 while (rprotolist_here != rprotolist_end) {
283 if ((*rprotolist_here).p != NULL) {
284
285 text_tarray collist;
286 comerror_t err;
287 (*rprotolist_here).p->get_collection_list (collist, err, logout);
288 if (err == noError) {
289 text_tarray::iterator collist_here = collist.begin();
290 text_tarray::iterator collist_end = collist.end();
291
292 int count = 0;
293 bool first = true;
294 while (collist_here != collist_end) {
295 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
296
297 if (cinfo != NULL) {
298 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
299
300 text_t coll_type = "&ct=";
301 if (cinfo->buildType == "mgpp") {
302 coll_type += "1&qto=";
303
304 // now we also want to check search types to set the qto arg
305 if (cinfo->searchTypes.size() == 0) {
306 coll_type += "3"; // default to 3 (= both)
307 } else {
308 unsigned int search_types = 0;
309 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
310 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
311
312 while (type_here != type_end) {
313 if (*type_here == "form") {
314 search_types |= 2;
315 } else if (*type_here == "plain") {
316 search_types |= 1;
317 }
318 type_here ++;
319 }
320 coll_type += search_types;
321 if (search_types == 3) {
322 // both were specified, now need to look at the order to see which is the default
323 type_here = cinfo->searchTypes.begin();
324 if (*type_here == "form") {
325 coll_type += "&qt=1"; // set the default to form
326 }
327 }
328
329 }
330 }
331 else {
332 coll_type += "0";
333 }
334
335 found_valid_col = true;
336 FilterResponse_t response;
337 text_tset metadata;
338 metadata.insert ("collectionname");
339 metadata.insert ("iconcollection");
340 metadata.insert ("iconcollectionsmall");
341 // also look for lang specific values
342 text_t lang = args["l"];
343 if (!lang.empty()) {
344 metadata.insert ("collectionname:"+lang);
345 metadata.insert ("iconcollection:"+lang);
346 metadata.insert ("iconcollectionsmall:"+lang);
347 }
348 text_t collectionname = *collist_here;
349 text_t alt = collectionname;
350
351 if (get_info ("collection", *collist_here, "", metadata, false,
352 (*rprotolist_here).p, response, logout)) {
353 // get the "collectionname"
354 if (!lang.empty() && !response.docInfo[0].metadata["collectionname:"+lang].values[0].empty()) {
355 alt = response.docInfo[0].metadata["collectionname:"+lang].values[0];
356 } else if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
357 alt = response.docInfo[0].metadata["collectionname"].values[0];
358 }
359
360 text_t iconurl;
361 iconurl.clear();
362
363 if (!lang.empty() &&!response.docInfo[0].metadata["iconcollectionsmall:"+lang].values[0].empty()) {
364 iconurl = response.docInfo[0].metadata["iconcollectionsmall:"+lang].values[0];
365 } else if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) {
366 iconurl = response.docInfo[0].metadata["iconcollectionsmall"].values[0];
367 } else if (!lang.empty() && !response.docInfo[0].metadata["iconcollection:"+lang].values[0].empty()) {
368 iconurl = response.docInfo[0].metadata["iconcollection:"+lang].values[0];
369 } else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) {
370 iconurl = response.docInfo[0].metadata["iconcollection"].values[0];
371 }
372
373 if (!iconurl.empty())
374 {
375 // check to see URL is local to colserver
376 text_t::iterator iconurl_head = iconurl.begin();
377 text_t iconhead = substr(iconurl_head,iconurl_head+16);
378 if (iconhead=="_httpcollection_")
379 {
380 // local and using _httpcollection_
381 text_t icontail = substr(iconurl_head+16,iconurl.end());
382 iconurl = "http://" + cinfo->httpdomain
383 + cinfo->httpprefix + "/collect/"
384 + *collist_here + "/" + icontail;
385 }
386 else if (iconurl[0]=='/')
387 {
388 // local but with full path
389 iconurl = "http://" + cinfo->httpdomain + iconurl;
390 }
391
392 collectionname
393 = "<img width=150 border=1 src=\"" + iconurl + "\" alt=\"" + alt + "\">";
394 }
395 else
396 {
397 collectionname = alt;
398 }
399
400 }
401 if ((count%configinfo.HomePageCols == 0) && (!first))
402 homeextra += "</tr><tr valign=top>\n";
403
404 comerror_t err;
405 text_t optsite = g_EmptyText;
406 text_t site_name = (*rprotolist_here).p->get_site_name (err);
407 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
408
409 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type;
410 link += "&l=" + args["l"] + "&w=" + args["w"] + "\">";
411
412 if (!cinfo->receptionist.empty())
413 link = "<a href=\"" + cinfo->receptionist + "\">";
414
415 homeextra += "<td>" + link + collectionname + "</a></td>\n";
416
417 count ++;
418 first = false;
419 }
420 }
421 collist_here ++;
422 }
423
424 for (; count%configinfo.HomePageCols != 0; count ++) homeextra += "<td></td>\n";
425 }
426 }
427 homeextra += "</td></tr>\n<tr>\n";
428 rprotolist_here ++;
429 }
430
431 if (!found_valid_col) {
432 homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
433 }
434 homeextra += "</tr></table></center>\n";
435 disp.setmacro ("homeextra", "home", homeextra);
436}
437
438void pageaction::set_collectionlist_macro (displayclass &disp, recptprotolistclass *protos,
439 ostream &logout) {
440
441 text_t collectionlist;
442 int count = 0;
443
444 recptprotolistclass::iterator rprotolist_here = protos->begin();
445 recptprotolistclass::iterator rprotolist_end = protos->end();
446 while (rprotolist_here != rprotolist_end) {
447 if ((*rprotolist_here).p != NULL) {
448
449 text_tarray collist;
450 comerror_t err;
451 (*rprotolist_here).p->get_collection_list (collist, err, logout);
452 if (err == noError) {
453 text_tarray::iterator collist_here = collist.begin();
454 text_tarray::iterator collist_end = collist.end();
455
456 while (collist_here != collist_end) {
457 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
458
459 if (cinfo != NULL) {
460 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
461
462 count ++;
463
464 text_t coll_type = "&ct=";
465 if (cinfo->buildType == "mgpp") {
466 coll_type += "1&qto=";
467
468 // now we also want to check search types to set the qto arg
469 if (cinfo->searchTypes.size() == 0) {
470 coll_type += "3"; // default to 2 (= both)
471 } else {
472 int search_types = 0;
473 text_tarray::const_iterator type_here = cinfo->searchTypes.begin();
474 text_tarray::const_iterator type_end = cinfo->searchTypes.end();
475
476 while (type_here != type_end) {
477 if (*type_here == "form") {
478 search_types |= 0x10;
479 } else if (*type_here == "plain") {
480 search_types |= 0x01;
481 }
482 type_here ++;
483 }
484 coll_type += search_types;
485
486 if (search_types == 3) {
487 // both were specified, now need to look at the order to see which is the default
488 type_here = cinfo->searchTypes.begin();
489 if (*type_here == "form") {
490 coll_type += "&qt=1"; // set the default to form
491 }
492 }
493 }
494 }
495 else {
496 coll_type += "0";
497 }
498 FilterResponse_t response;
499 text_tset metadata;
500 metadata.insert ("collectionname");
501 text_t collectionname = *collist_here;
502
503 if (get_info ("collection", *collist_here, "", metadata, false,
504 (*rprotolist_here).p, response, logout)) {
505 if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
506 collectionname = response.docInfo[0].metadata["collectionname"].values[0];
507 }
508 }
509
510 comerror_t err;
511 text_t optsite = g_EmptyText;
512 text_t site_name = (*rprotolist_here).p->get_site_name (err);
513 if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
514
515 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type+"\">";
516
517 if (!cinfo->receptionist.empty())
518 link = "<a href=\"" + cinfo->receptionist + "\">";
519
520 collectionlist += "<li>" + link + collectionname + "</a>\n";
521 }
522 }
523 collist_here ++;
524 }
525 }
526 }
527 rprotolist_here ++;
528 }
529
530 if (count == 1) {
531 collectionlist = "<p>_text1coll_\n<ul>" +
532 collectionlist + "</ul>\n";
533 } else if (count > 1) {
534 collectionlist = "<p>_textmorecolls_(" + text_t(count) +
535 ")\n<ul>" + collectionlist + "</ul>\n";
536 }
537
538 disp.setmacro ("collectionlist", "homehelp", collectionlist);
539}
540
541void pageaction::set_documentation_macro (displayclass &disp) {
542
543 text_t documentation;
544 text_t docsdir = filename_cat(gsdlhome, "docs");
545
546 if (file_exists(filename_cat(docsdir, "User.pdf"))) {
547 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/User.pdf\">_iconpdf_"
548 "</a></td><td>_textuserguide_</td></tr>";
549 }
550
551 if (file_exists(filename_cat(docsdir, "Install.pdf"))) {
552 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Install.pdf\">_iconpdf_"
553 "</a></td><td>_textinstallerguide_</td></tr>";
554 }
555
556 if (file_exists(filename_cat(docsdir, "Develop.pdf"))) {
557 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Develop.pdf\">_iconpdf_"
558 "</a></td><td>_textdeveloperguide_</td></tr>";
559 }
560
561 if (file_exists(filename_cat(docsdir, "Paper.pdf"))) {
562 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Paper.pdf\">_iconpdf_"
563 "</a></td><td>_textpaperguide_</td></tr>";
564 }
565
566 if (file_exists(filename_cat(docsdir, "Organize.pdf"))) {
567 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Organize.pdf\">_iconpdf_"
568 "</a></td><td>_textorganizerguide_</td></tr>";
569 }
570
571 if (!documentation.empty()) {
572 disp.setmacro("documentation", "docs", "<p>\n<table border=0>\n" + documentation + "\n</table>\n");
573 }
574}
575
576void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
577 const text_t &packagename, const text_t &filename) {
578
579 text_t filecontent;
580 char *filenamec = filename.getcstr();
581 ifstream file_in (filenamec);
582 delete filenamec;
583 if (file_in) {
584 char c;
585 file_in.get(c);
586 while (!file_in.eof ()) {
587 if (c == '\n') filecontent += "<br>";
588 filecontent.push_back(c);
589 file_in.get(c);
590 }
591 file_in.close();
592 }
593 disp.setmacro (macroname, packagename, dm_safe(filecontent));
594}
595
596void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
597 recptprotolistclass *protos, ColInfoResponse_t *cinfo,
598 ostream &logout) {
599 // _languageoption_
600 // Create the "interface language" selection box for the preferences
601 // pages. You can use something like "format PreferenceLanguages
602 // en|fr|zn" from within a collect.cfg file to use only a subset of
603 // the available languages for any given collection (for
604 // collection-specific preferences pages). This facility is kind of
605 // ugly though and should be replaced by something better when the
606 // configuration files are tidied up (as should all the other
607 // "format Preference..." options).
608 text_t &arg_l = args["l"];
609 const recptconf &configinfo = recpt->get_configinfo();
610 // put languages in another map to sort them by longname
611 text_tmap languages;
612 languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
613 languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
614 while (thislang != endlang) {
615 languages[(*thislang).second.longname] = (*thislang).first;
616 thislang++;
617 }
618 text_tmap::iterator tlang = languages.begin();
619 text_tmap::iterator elang = languages.end();
620
621 text_t languageoption;
622 bool collection_specific = false;
623
624 if (cinfo != NULL) {
625 text_tmap::const_iterator it = cinfo->format.find ("PreferenceLanguages");
626 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
627 collection_specific = true;
628 text_tset pref_langs;
629 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
630 if (pref_langs.size() > 1) {
631 while (tlang != elang) {
632 if (pref_langs.find((*tlang).second) != pref_langs.end()) {
633 languageoption += "<option value=\"" + (*tlang).second + "\"";
634 if ((*tlang).second == arg_l) languageoption += " selected";
635 languageoption += ">" + (*tlang).first + "\n";
636 }
637 tlang ++;
638 }
639 }
640 }
641 }
642
643 if (!collection_specific) {
644 while (tlang != elang) {
645 languageoption += "<option value=\"" + (*tlang).second + "\"";
646 if ((*tlang).second == arg_l) languageoption += " selected";
647 languageoption += ">" + (*tlang).first + "\n";
648 tlang ++;
649 }
650 }
651
652 if (!languageoption.empty()) {
653 languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
654 languageoption += "</select>\n";
655 disp.setmacro ("languageoption", args["p"], languageoption);
656 }
657
658 // _encodingoption_
659 // create the "encoding" selection box for the preferences page
660 if (configinfo.encodings.size() > 1) {
661 text_t &arg_w = args["w"];
662 text_t encodingoption;
663 text_tmap::const_iterator thisenc = configinfo.encodings.begin();
664 text_tmap::const_iterator endenc = configinfo.encodings.end();
665 while (thisenc != endenc) {
666 encodingoption += "<option value=\"" + (*thisenc).second + "\"";
667 if ((*thisenc).second == arg_w) encodingoption += " selected";
668 encodingoption += ">" + (*thisenc).first + "\n";
669 thisenc ++;
670 }
671
672 encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
673 encodingoption += "</select>\n";
674 disp.setmacro ("encodingoption", args["p"], encodingoption);
675 }
676}
677
678void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
679 recptprotolistclass *protos, ostream &logout) {
680
681 // define_internal_macros sets the following macros:
682
683 // _numdocs_ the number of documents in the collection
684
685 // _builddate_ the date last built
686
687 // if page is "home"
688 // _homeextra_ this is the list of available collections and collection info
689 // to be displayed on the home page
690
691
692 // if page is "preferences"
693 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
694
695 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
696
697 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
698
699
700 // if page is "preferences" or "homepref"
701 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
702
703 // _encodingoption_ encodings to select from
704
705
706 // if page is "about"
707 // _textsubcollections_ the text on which subcollections make up the collection (if
708 // cross-collection searching is being used
709
710 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
711
712 // _numbrowseoptions_ the number of browsing options
713
714 // _prefschanged_ will be set to _textprefschanged_ if the "set preferences" button
715 // was pressed
716
717 // _aboutqueryform_ will be set to "" if the collection isn't searchable
718
719 // if page is "help"
720 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
721
722 // _numbrowseoptions_ the number of browsing options
723
724 // _topicreadingdocs_ this section of the help text differs depending on what type of
725 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
726 // _texthelpreadingdocs_
727
728 // if page is "home" or "homehelp"
729 // _textgocollector_ set to "" if collector is disabled in main.cfg
730 // _textgoadmin_ set to "" if status is disabled in main.cfg
731 // _textgotranslator_ set to "" if translator is disabled in main.cfg
732
733
734 // if page is "homehelp"
735 // _collectionlist_ list of available collections to be displayed on the homehelp page
736
737
738 // if page is "docs"
739 // _documentation_ links to PDF documents if they're available
740
741
742 // if page is "bsummary"
743 // _importlog_ set to contents of collections import.log file
744 // _faillog_ set to contents of collections fail.log file
745
746
747 if (recpt == NULL) {
748 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
749 << " information about any receptionists. The method set_receptionist was\n"
750 << " probably not called from the module which instantiated this action.\n";
751 return;
752 }
753
754 text_t &arg_p = args["p"];
755 text_t &arg_c = args["c"];
756 ColInfoResponse_t *cinfo = NULL;
757
758 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
759 if (collectproto != NULL) {
760 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
761
762 disp.setmacro ("numdocs", displayclass::defaultpackage, cinfo->numDocs);
763 unsigned long current_time = time(NULL);
764 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
765 disp.setmacro ("builddate", displayclass::defaultpackage, builddate);
766
767 text_t numbytes;
768 if ((cinfo->numBytes/(1024*1024)) > 1) {
769 numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
770 } else if ((cinfo->numBytes/1024) > 1) {
771 numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
772 } else {
773 numbytes = (text_t)cinfo->numBytes + " bytes";
774 }
775 disp.setmacro("numbytes", displayclass::defaultpackage, numbytes);
776 }
777
778 //setting _queryformcontent_ so that the query interface is consistent.
779 //also adding usability button if necessary
780 if (arg_p == "about") {
781 if (cinfo == NULL) {
782 disp.setmacro("cvariable", displayclass::defaultpackage, arg_c);
783 disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
784 return;
785 }
786 else {
787
788 text_tmap::iterator check = cinfo->format.find("QueryInterface");
789 if(check != cinfo->format.end()){
790 if((*check).second=="DateSearch"){
791 text_t current = "_datesearch_";
792 disp.setmacro("optdatesearch","query",current);
793 }
794 }
795 check = cinfo->format.find("Usability");
796 if(check != cinfo->format.end()){
797 disp.setmacro("usability", displayclass::defaultpackage, "_imageusab_");
798 disp.setmacro("usabinterface", displayclass::defaultpackage, ("_usab"+(*check).second+"_"));
799 disp.setmacro("usabilityscript", displayclass::defaultpackage, "_usabshowscript_");
800 }
801 }
802 }
803
804 if (arg_p == "home" || arg_p == "homehelp") {
805 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
806 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
807 if (translator_disabled) disp.setmacro ("textgotranslator", "home", "");
808
809 if (arg_p == "home") {
810 homepagestyle (disp, protos, args, logout);
811 } else if (arg_p == "homehelp") {
812 set_collectionlist_macro (disp, protos, logout);
813 }
814
815 } else if (arg_p == "homepref") {
816
817 // set _languageoption_ and _encodingoption_
818 set_language_encoding_macros(disp, args, protos, cinfo, logout);
819
820 } else if (arg_p == "preferences") {
821
822 if (cinfo == NULL) {
823 disp.setmacro("cvariable", displayclass::defaultpackage, arg_c);
824 disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
825 return;
826 }
827
828 if (collectproto == NULL) {return;}
829
830 // set _languageoption_ and _encodingoption_
831 set_language_encoding_macros(disp, args, protos, cinfo, logout);
832
833 // _collectionoption_
834 if ((args["ccs"] == "1") && (cinfo->ccsCols.size() > 1)) {
835 text_t collectionoption = "_textcollectionoption_";
836 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
837 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
838 int count = 0;
839 while (col_here != col_end) {
840 text_t colname;
841 if (*col_here == arg_c) {
842 colname = cinfo->collectionmeta["collectionname"];
843 } else {
844 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
845 if (this_cinfo == NULL) {col_here ++; continue;}
846 colname = this_cinfo->collectionmeta["collectionname"];
847 }
848
849 count ++;
850 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
851 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
852 colname + "<br>\n";
853 col_here ++;
854 }
855
856 if (count > 1)
857 disp.setmacro ("collectionoption", "preferences", collectionoption);
858 }
859
860 // _htmloptions_
861
862 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
863 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
864 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
865
866
867 // _PreferenceDocsFromWeb_
868
869 it = cinfo->format.find ("PreferenceDocsFromWeb");
870 if ((it == cinfo->format.end()) || ((*it).second == "true"))
871 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
872 }
873
874 // _prefschanged_
875 if (!args["bp"].empty()) {
876 disp.setmacro ("prefschanged", "preferences", "_textprefschanged_");
877 }
878
879 } else if (arg_p == "about" || arg_p == "help") {
880 if (collectproto == NULL) return;
881
882 comerror_t err;
883 bool has_search_button = true;
884 collectproto->is_searchable(args["c"], has_search_button, err, logout);
885 if (err != noError) has_search_button = true;
886
887 // _textbrowseoptions_ and _numbrowseoptions_
888
889 FilterResponse_t response;
890 text_tset metadata;
891 metadata.insert ("Title");
892 //****************
893 metadata.insert ("childtype");
894 //****************
895 bool getParents = false;
896 get_children ("", args["c"], args["l"], metadata, getParents, collectproto, response, logout);
897
898 int numbrowseoptions = response.docInfo.size();
899 if (has_search_button) numbrowseoptions += 1;
900 disp.setmacro ("numbrowseoptions", "help", numbrowseoptions);
901
902 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
903 ResultDocInfo_tarray::iterator end = response.docInfo.end();
904
905 text_t shorttext;
906 text_t longtext;
907 if (has_search_button) {
908 shorttext = "<ul><li>_textSearchshort_\n";
909 longtext = "_textSearchlong_";
910 }
911
912 // ********************************
913 int classifiernumber = 0;
914 bool collage = false;
915
916 while (here != end) {
917
918 classifiernumber++;
919 text_t childtype = (*here).metadata["childtype"].values[0];
920 if (childtype == "Collage" && arg_p == "about") {
921 // get the classifier number
922 disp.setmacro ("classifier", "about", classifiernumber);
923 disp.setmacro ("aboutCollage", "about", "_collageapplet_");
924 collage = true;
925 }
926 here ++;
927 }
928 if (! collage)
929 disp.setmacro ("aboutCollage", "about", "_collageempty_");
930
931 // ********************************
932
933 here = response.docInfo.begin();
934
935 while (here != end) {
936
937 text_t title = (*here).metadata["Title"].values[0];
938
939 text_t stext, ltext;
940 disp.expandstring ("help", "_text" + title + "short_", stext);
941 if (stext == ("_text" + title + "short_")) {
942 shorttext += "<li>_help:textdefaultshorttext_";
943 longtext += "_help:textdefaultlongtext_";
944 } else {
945 shorttext += "<li>_help:text" + title + "short_";
946 longtext += "_help:text" + title + "long_";
947 }
948
949 here ++;
950 }
951 shorttext += "</ul>\n";
952 if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
953 else disp.setmacro ("textbrowseoptions", "help", longtext);
954
955 if (arg_p == "about") {
956
957 // _textsubcollections_
958 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
959 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
960 text_tarray::const_iterator here = cinfo->ccsCols.begin();
961 text_tarray::const_iterator end = cinfo->ccsCols.end();
962 bool first = true;
963 int count = 0;
964 while (here != end) {
965 if (*here == arg_c) {
966 if (!first) textsubcollections += "<br>";
967 textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
968 } else {
969 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
970 if (this_cinfo == NULL) {here ++; continue;}
971 if (!first) textsubcollections += "<br>";
972 textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
973 }
974 count ++;
975 first = false;
976 here ++;
977 }
978 textsubcollections += "_textsubcols2_";
979 if (count > 1) {
980 disp.setmacro ("textsubcollections", "about", textsubcollections);
981 }
982 }
983
984 comerror_t err;
985 bool issearchable = true;
986 collectproto->is_searchable(args["c"], issearchable, err, logout);
987 if (err != noError) issearchable = true;
988 outconvertclass t;
989 if (!issearchable) {
990 disp.setmacro ("aboutqueryform", "about", "");
991 }
992 }
993
994 } else if (arg_p == "docs") {
995
996 set_documentation_macro (disp);
997
998 } else if (arg_p == "bsummary" && !arg_c.empty()) {
999
1000 set_macro_to_file_contents (disp, "importlog", "bsummary",
1001 filename_cat(gsdlhome, "collect", arg_c, "etc", "import.log"));
1002 set_macro_to_file_contents (disp, "faillog", "bsummary",
1003 filename_cat(gsdlhome, "collect", arg_c, "etc", "fail.log"));
1004 }
1005}
1006
1007bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
1008 browsermapclass * /*browsers*/, displayclass &disp,
1009 outconvertclass &outconvert, ostream &textout,
1010 ostream &/*logout*/) {
1011
1012 text_t &arg_p = args["p"];
1013
1014 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
1015 << ("_" + arg_p + ":content_\n")
1016 << ("_" + arg_p + ":footer_\n");
1017
1018 return true;
1019}
1020
1021void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
1022 if ((key == "status") && (cfgline.size() == 1) &&
1023 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
1024 status_disabled = false;
1025 } else if ((key == "collector") && (cfgline.size() == 1) &&
1026 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
1027 collector_disabled = false;
1028 } else if ((key == "translator") && (cfgline.size() == 1) &&
1029 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
1030 translator_disabled = false;
1031 } else {
1032 // call the parent class to deal with the things which
1033 // are not dealt with here
1034 action::configure (key, cfgline);
1035 }
1036}
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
Note: See TracBrowser for help on using the repository browser.