source: gsdl/trunk/runtime-src/src/recpt/pageaction.cpp@ 18481

Last change on this file since 18481 was 18481, checked in by davidb, 12 years ago

missing space in attributes to html tag

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