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

Last change on this file since 7762 was 7762, checked in by davidb, 20 years ago

'gliapplet' flag added -- in comparable style of 'collector' flag --
to control whether applet version of GLI is enabled/disabled in
greenstone installation.

CVS: ----------------------------------------------------------------------

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