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

Last change on this file since 13982 was 13982, checked in by lh92, 17 years ago

Added UseBook variable for Realistic Book

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 32.1 KB
Line 
1/**********************************************************************
2 *
3 * pageaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26// 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 "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 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
183
184 if (cinfo != NULL) {
185 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
186
187 text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
188 if (collectionname.empty()) {
189 collectionname = *collist_here;
190 }
191
192 comerror_t err;
193 text_t optsite = g_EmptyText;
194 text_t site_name = (*rprotolist_here).p->get_site_name (err);
195 if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; }
196
197 text_t link = "_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here;
198 link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"];
199
200 // We are "dynamically" overriding so to speak the
201 // link to the collection aka receptionist.
202
203 if (!cinfo->receptionist.empty())
204 link = cinfo->receptionist;
205
206
207 homeextra += "<option value=\"" + link + "\"";
208 homeextra += ">" + collectionname + "</option>\n";
209
210 }
211
212 ++collist_here;
213 }
214
215 }
216 }
217 ++rprotolist_here;
218 }
219
220 }
221 homeextra += "</select>\n";
222 homeextra += "</form>\n";
223
224 disp.setmacro ("homeextra", "home", homeextra);
225}
226
227// originally called set_homeextra_macro
228// this function displays the Greenstone
229// main page as usual with the graphics for
230// the collections.
231
232// Aly Dharshi
233// 11th July 2003
234
235void pageaction::home_images(displayclass &disp, recptprotolistclass *protos,
236 cgiargsclass &args, const recptconf &configinfo,
237 ostream &logout) {
238
239 text_t homeextra = "<table class=\"collections\">\n";
240 bool found_valid_col = false;
241 recptprotolistclass::iterator rprotolist_here = protos->begin();
242 recptprotolistclass::iterator rprotolist_end = protos->end();
243 while (rprotolist_here != rprotolist_end) {
244 if ((*rprotolist_here).p != NULL) {
245
246 text_tarray collist;
247 comerror_t err;
248 (*rprotolist_here).p->get_collection_list (collist, err, logout);
249 if (err == noError) {
250 text_tarray::iterator collist_here = collist.begin();
251 text_tarray::iterator collist_end = collist.end();
252
253 int count = 0;
254 while (collist_here != collist_end) {
255 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
256
257 if (cinfo != NULL) {
258 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
259
260 found_valid_col = true;
261 text_t collectionname = *collist_here;
262 text_t alt = cinfo->get_collectionmeta("collectionname", args["l"]);
263 if (alt.empty()) {
264 alt = collectionname;
265 }
266
267 // url to image: try iconcollectionsmall, then iconcollection
268 text_t iconurl = cinfo->get_collectionmeta("iconcollectionsmall", args["l"]);
269 if (iconurl.empty()) {
270 iconurl = cinfo->get_collectionmeta("iconcollection", args["l"]);
271 }
272
273 if (!iconurl.empty()) {
274
275 // check to see URL is local to colserver
276 text_t::iterator iconurl_head = iconurl.begin();
277 text_t iconhead = substr(iconurl_head,iconurl_head+16);
278 if (iconhead=="_httpcollection_") {
279
280 // local and using _httpcollection_
281 text_t icontail = substr(iconurl_head+16,iconurl.end());
282 iconurl = "http://" + cinfo->httpdomain
283 + cinfo->httpprefix + "/collect/"
284 + *collist_here + "/" + icontail;
285 }
286 else if (iconurl[0]=='/') {
287
288 // local but with full path
289 iconurl = "http://" + cinfo->httpdomain + iconurl;
290 }
291
292 collectionname
293 = "<img width=\"150\" src=\"" + iconurl + "\" alt=\"" + alt + "\">";
294 } else {
295 collectionname = alt;
296 }
297
298 if (count%configinfo.HomePageCols == 0)
299 homeextra += "<tr valign=\"top\">\n";
300
301 comerror_t err;
302 text_t optsite = g_EmptyText;
303 text_t site_name = (*rprotolist_here).p->get_site_name (err);
304 if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; }
305
306 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here;
307 link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">";
308
309 if (!cinfo->receptionist.empty())
310 link = "<a href=\"" + cinfo->receptionist + "\">";
311
312 homeextra += "<td>" + link + collectionname + "</a></td>\n";
313
314 ++count;
315 if (count%configinfo.HomePageCols == 0)
316 homeextra += "</tr>\n";
317 }
318 }
319 ++collist_here;
320 }
321
322 // Finish off the last row, if necessary
323 if (count%configinfo.HomePageCols != 0) {
324 while (count%configinfo.HomePageCols != 0) {
325 homeextra += "<td></td>\n";
326 ++count;
327 }
328 homeextra += "</tr>\n";
329 }
330 }
331 }
332 ++rprotolist_here;
333 }
334
335 if (!found_valid_col) {
336 homeextra += "<tr><td>_textnocollections_</td></tr>\n";
337 }
338 homeextra += "</table>\n";
339 disp.setmacro ("homeextra", "home", homeextra);
340}
341
342void pageaction::set_collectionlist_macro (displayclass &disp,
343 recptprotolistclass *protos,
344 cgiargsclass &args,
345 ostream &logout) {
346
347 text_t collectionlist;
348 int count = 0;
349
350 recptprotolistclass::iterator rprotolist_here = protos->begin();
351 recptprotolistclass::iterator rprotolist_end = protos->end();
352 while (rprotolist_here != rprotolist_end) {
353 if ((*rprotolist_here).p != NULL) {
354
355 text_tarray collist;
356 comerror_t err;
357 (*rprotolist_here).p->get_collection_list (collist, err, logout);
358 if (err == noError) {
359 text_tarray::iterator collist_here = collist.begin();
360 text_tarray::iterator collist_end = collist.end();
361
362 while (collist_here != collist_end) {
363 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
364
365 if (cinfo != NULL) {
366 if (cinfo->isPublic && (cinfo->buildDate > 0)) {
367
368 ++count;
369
370 text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
371 if (collectionname.empty()) {
372 collectionname = *collist_here;
373 }
374
375 comerror_t err;
376 text_t optsite = g_EmptyText;
377 text_t site_name = (*rprotolist_here).p->get_site_name (err);
378 if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; }
379
380 text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + "\">";
381
382 if (!cinfo->receptionist.empty())
383 link = "<a href=\"" + cinfo->receptionist + "\">";
384
385 collectionlist += "<li>" + link + collectionname + "</a>\n";
386 }
387 }
388 ++collist_here;
389 }
390 }
391 }
392 ++rprotolist_here;
393 }
394
395 if (count == 1) {
396 collectionlist = "<p>_text1coll_\n<ul>" +
397 collectionlist + "</ul>\n";
398 } else if (count > 1) {
399 collectionlist = "<p>_textmorecolls_(" + text_t(count) +
400 ")\n<ul>" + collectionlist + "</ul>\n";
401 }
402
403 disp.setmacro ("collectionlist", "homehelp", collectionlist);
404}
405
406void pageaction::set_documentation_macro (displayclass &disp) {
407
408 text_t documentation;
409 text_t docsdir = filename_cat(gsdlhome, "docs");
410
411 if (file_exists(filename_cat(docsdir, "User.pdf"))) {
412 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/User.pdf\">_iconpdf_"
413 "</a></td><td>_textuserguide_</td></tr>";
414 }
415
416 if (file_exists(filename_cat(docsdir, "Install.pdf"))) {
417 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Install.pdf\">_iconpdf_"
418 "</a></td><td>_textinstallerguide_</td></tr>";
419 }
420
421 if (file_exists(filename_cat(docsdir, "Develop.pdf"))) {
422 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Develop.pdf\">_iconpdf_"
423 "</a></td><td>_textdeveloperguide_</td></tr>";
424 }
425
426 if (file_exists(filename_cat(docsdir, "Paper.pdf"))) {
427 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Paper.pdf\">_iconpdf_"
428 "</a></td><td>_textpaperguide_</td></tr>";
429 }
430
431 if (file_exists(filename_cat(docsdir, "Organize.pdf"))) {
432 documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Organize.pdf\">_iconpdf_"
433 "</a></td><td>_textorganizerguide_</td></tr>";
434 }
435
436 if (!documentation.empty()) {
437 disp.setmacro("documentation", "docs", "<p>\n<table border=0>\n" + documentation + "\n</table>\n");
438 }
439}
440
441void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
442 const text_t &packagename, const text_t &filename) {
443
444 text_t filecontent;
445 char *filenamec = filename.getcstr();
446 ifstream file_in (filenamec);
447 delete []filenamec;
448 if (file_in) {
449 char c;
450 file_in.get(c);
451 while (!file_in.eof ()) {
452 if (c == '\n') filecontent += "<br>";
453 filecontent.push_back(c);
454 file_in.get(c);
455 }
456 file_in.close();
457 }
458 disp.setmacro (macroname, packagename, dm_safe(filecontent));
459}
460
461void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
462 recptprotolistclass *protos, ColInfoResponse_t *cinfo,
463 ostream &logout) {
464 // _languageoption_
465 // Create the "interface language" selection box for the preferences
466 // pages. You can use something like "format PreferenceLanguages
467 // en|fr|zn" from within a collect.cfg file to use only a subset of
468 // the available languages for any given collection (for
469 // collection-specific preferences pages). This facility is kind of
470 // ugly though and should be replaced by something better when the
471 // configuration files are tidied up (as should all the other
472 // "format Preference..." options).
473 text_t &arg_l = args["l"];
474 const recptconf &configinfo = recpt->get_configinfo();
475 // put languages in another map to sort them by longname
476 text_tmap languages;
477 languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
478 languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
479 while (thislang != endlang) {
480 languages[(*thislang).second.longname] = (*thislang).first;
481 ++thislang;
482 }
483 text_tmap::iterator tlang = languages.begin();
484 text_tmap::iterator elang = languages.end();
485
486 text_t languageoption;
487 bool collection_specific = false;
488
489 if (cinfo != NULL) {
490 text_tmap::const_iterator it = cinfo->format.find ("PreferenceLanguages");
491 if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
492 collection_specific = true;
493 text_tset pref_langs;
494 splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
495 if (pref_langs.size() > 1) {
496 while (tlang != elang) {
497 if (pref_langs.find((*tlang).second) != pref_langs.end()) {
498 languageoption += "<option value=\"" + (*tlang).second + "\"";
499 if ((*tlang).second == arg_l) languageoption += " selected";
500 languageoption += ">" + (*tlang).first + "</option>\n";
501 }
502 ++tlang;
503 }
504 }
505 }
506 }
507
508 if (!collection_specific) {
509 while (tlang != elang) {
510 languageoption += "<option value=\"" + (*tlang).second + "\"";
511 if ((*tlang).second == arg_l) languageoption += " selected";
512 languageoption += ">" + (*tlang).first + "</option>\n";
513 ++tlang;
514 }
515 }
516
517 if (!languageoption.empty()) {
518 languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
519 languageoption += "</select>\n";
520 disp.setmacro ("languageoption", args["p"], languageoption);
521 }
522
523 // _encodingoption_
524 // create the "encoding" selection box for the preferences page
525 if (configinfo.encodings.size() > 1) {
526 text_t &arg_w = args["w"];
527 text_t encodingoption;
528 text_tmap::const_iterator thisenc = configinfo.encodings.begin();
529 text_tmap::const_iterator endenc = configinfo.encodings.end();
530 while (thisenc != endenc) {
531 encodingoption += "<option value=\"" + (*thisenc).second + "\"";
532 if ((*thisenc).second == arg_w) encodingoption += " selected";
533 encodingoption += ">" + (*thisenc).first + "</option>\n";
534 ++thisenc;
535 }
536
537 encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
538 encodingoption += "</select>\n";
539 disp.setmacro ("encodingoption", args["p"], encodingoption);
540 } else if (configinfo.encodings.size() == 1) {
541 text_t encodingoption;
542 text_tmap::const_iterator thisenc = configinfo.encodings.begin();
543 encodingoption = (*thisenc).first;
544 disp.setmacro ("encodingoption", args["p"], encodingoption);
545 } else { // size == 0. shouldn't really happen, but allow it
546 disp.setmacro ("encodingoption", args["p"], "None");
547 }
548
549}
550
551
552void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
553 recptprotolistclass *protos, ostream &logout) {
554
555 // define_internal_macros sets the following macros:
556
557 // _numdocs_ the number of documents in the collection
558
559 // _builddate_ the date last built
560
561 // if page is "home"
562 // _homeextra_ this is the list of available collections and collection info
563 // to be displayed on the home page
564
565
566 // if page is "preferences"
567 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
568
569 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
570
571 // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
572
573
574 // if page is "preferences" or "homepref"
575 // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
576
577 // _encodingoption_ encodings to select from
578
579
580 // if page is "about"
581 // _textsubcollections_ the text on which subcollections make up the collection (if
582 // cross-collection searching is being used
583
584 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
585
586 // _numbrowseoptions_ the number of browsing options
587
588 // _prefschanged_ will be set to _textprefschanged_ if the "set preferences" button
589 // was pressed
590
591 // _aboutqueryform_ will be set to "" if the collection isn't searchable
592
593 // if page is "help"
594 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
595
596 // _numbrowseoptions_ the number of browsing options
597
598 // _topicreadingdocs_ this section of the help text differs depending on what type of
599 // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
600 // _texthelpreadingdocs_
601
602 // if page is "home" or "homehelp"
603 // _textgocollector_ set to "" if collector is disabled in main.cfg
604 // _textgodepositor_ set to "" if depositor is disabled in main.cfg
605 // _textgoadmin_ set to "" if status is disabled in main.cfg
606 // _textgotranslator_ set to "" if translator is disabled in main.cfg
607 // _textgogliapplet_ set to "" if gliapplet is disabled in main.cfg
608
609
610 // if page is "homehelp"
611 // _collectionlist_ list of available collections to be displayed on the homehelp page
612
613
614 // if page is "docs"
615 // _documentation_ links to PDF documents if they're available
616
617
618 // if page is "bsummary"
619 // _importlog_ set to contents of collections import.log file
620 // _faillog_ set to contents of collections fail.log file
621 //_buildlog_ set to contents of collections build.log file
622
623 if (recpt == NULL) {
624 logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
625 << " information about any receptionists. The method set_receptionist was\n"
626 << " probably not called from the module which instantiated this action.\n";
627 return;
628 }
629 // _versionnnum_ greenstone version number (hard-coded)
630 disp.setmacro("versionnum", displayclass::defaultpackage, GSDL_VERSION);
631
632 text_t &arg_p = args["p"];
633 text_t &arg_c = args["c"];
634 ColInfoResponse_t *cinfo = NULL;
635
636 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
637 if (collectproto != NULL) {
638 cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
639
640 //set the tidyoption
641 if (cinfo->useBook == false)
642 {
643 disp.setmacro ("tidyoption", displayclass::defaultpackage, "untidy");
644 }
645 else
646 {
647 disp.setmacro ("tidyoption", displayclass::defaultpackage, "tidy");
648 }
649
650 disp.setmacro ("numdocs", displayclass::defaultpackage, cinfo->numDocs);
651 disp.setmacro ("numsections", displayclass::defaultpackage, cinfo->numSections);
652 disp.setmacro ("numwords", displayclass::defaultpackage, cinfo->numWords);
653 unsigned long current_time = time(NULL);
654 unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
655 disp.setmacro ("builddate", displayclass::defaultpackage, builddate);
656
657 text_t numbytes;
658 if ((cinfo->numBytes/(1024*1024)) > 1) {
659 numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
660 } else if ((cinfo->numBytes/1024) > 1) {
661 numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
662 } else {
663 numbytes = (text_t)cinfo->numBytes + " bytes";
664 }
665 disp.setmacro("numbytes", displayclass::defaultpackage, numbytes);
666
667 // set up ct, qt, qto
668 set_query_type_args(cinfo, args);
669 // set up ks, ss, afs
670 set_stem_index_args(cinfo, args);
671
672 }
673
674 //setting _queryformcontent_ so that the query interface is consistent.
675 //also adding usability button if necessary
676 if (arg_p == "about") {
677 if (cinfo == NULL) {
678 disp.setmacro("cvariable", displayclass::defaultpackage, arg_c);
679 disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
680 return;
681 }
682 else {
683
684 text_tmap::iterator check = cinfo->format.find("QueryInterface");
685 if(check != cinfo->format.end()){
686 if((*check).second=="DateSearch"){
687 text_t current = "_datesearch_";
688 disp.setmacro("optdatesearch","query",current);
689 }
690 }
691 check = cinfo->format.find("Usability");
692 if(check != cinfo->format.end()){
693 disp.setmacro("usability", displayclass::defaultpackage, "_usablink_");
694 disp.setmacro("usabinterface", displayclass::defaultpackage, ("_usab"+(*check).second+"_"));
695 disp.setmacro("usabilityscript", displayclass::defaultpackage, "_usabshowscript_");
696 }
697 }
698 }
699
700
701 if (arg_p == "home" || arg_p == "homehelp") {
702 if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
703 if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
704 if (depositor_disabled) disp.setmacro ("textgodepositor", "home", "");
705 if (translator_disabled) disp.setmacro ("textgotranslator", "home", "");
706
707 if (arg_p == "home") {
708 homepagestyle (disp, protos, args, logout);
709 } else if (arg_p == "homehelp") {
710 set_collectionlist_macro (disp, protos, args, logout);
711 }
712
713 } else if (arg_p == "gli") {
714 if (gliapplet_disabled) disp.setmacro ("gliapplet", "gli", "");
715
716 } else if (arg_p == "homepref") {
717
718 // set _languageoption_ and _encodingoption_
719 set_language_encoding_macros(disp, args, protos, cinfo, logout);
720
721 } else if (arg_p == "preferences") {
722
723 if (cinfo == NULL) {
724 disp.setmacro("cvariable", displayclass::defaultpackage, arg_c);
725 disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
726 return;
727 }
728
729 if (collectproto == NULL) {return;}
730
731 // set _languageoption_ and _encodingoption_
732 set_language_encoding_macros(disp, args, protos, cinfo, logout);
733
734 // _collectionoption_
735 if ((args["ccs"] == "1") && (cinfo->ccsCols.size() > 1)) {
736 text_t collectionoption = "_textcollectionoption_";
737 text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
738 text_tarray::const_iterator col_end = cinfo->ccsCols.end();
739 int count = 0;
740 while (col_here != col_end) {
741 text_t colname;
742 if (*col_here == arg_c) {
743 colname = cinfo->get_collectionmeta("collectionname", args["l"]);
744 } else {
745 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
746 if (this_cinfo == NULL) {++col_here; continue;}
747 colname = this_cinfo->get_collectionmeta("collectionname", args["l"]);
748 }
749 if (colname.empty()) {
750 colname = *col_here;
751 }
752 ++count;
753 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
754 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
755 colname + "<br>\n";
756 ++col_here;
757 }
758
759 if (count > 1)
760 disp.setmacro ("collectionoption", "preferences", collectionoption);
761 }
762
763 // _htmloptions_
764
765 text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
766 if ((it != cinfo->format.end()) && ((*it).second == "true")) {
767 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
768
769
770 // _PreferenceDocsFromWeb_
771
772 it = cinfo->format.find ("PreferenceDocsFromWeb");
773 if ((it == cinfo->format.end()) || ((*it).second == "true"))
774 disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
775 }
776
777 // _prefschanged_
778 if (!args["bp"].empty()) {
779 disp.setmacro ("prefschanged", "preferences", "_textprefschanged_");
780 }
781
782 } else if (arg_p == "about" || arg_p == "help") {
783 if (collectproto == NULL) return;
784
785 comerror_t err;
786 bool has_search_button = true;
787 collectproto->is_searchable(args["c"], has_search_button, err, logout);
788 if (err != noError) has_search_button = true;
789
790 // _textbrowseoptions_ and _numbrowseoptions_
791
792 FilterResponse_t response;
793 text_tset metadata;
794 metadata.insert ("Title");
795 //****************
796 metadata.insert ("childtype");
797 //****************
798 bool getParents = false;
799 get_children ("", args["c"], args["l"], metadata, getParents, collectproto, response, logout);
800
801 int numbrowseoptions = response.docInfo.size();
802 if (has_search_button) numbrowseoptions += 1;
803 disp.setmacro ("numbrowseoptions", "help", numbrowseoptions);
804
805 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
806 ResultDocInfo_tarray::iterator end = response.docInfo.end();
807
808 text_t helptext;
809 if (has_search_button) {
810 helptext = "<ul><li>_textSearchhelp_\n";
811 }
812
813 // ********************************
814 int classifiernumber = 0;
815 bool collage = false;
816
817 while (here != end) {
818
819 ++classifiernumber;
820 text_t childtype = (*here).metadata["childtype"].values[0];
821 if (childtype == "Collage" && arg_p == "about") {
822 // get the classifier number
823 disp.setmacro ("classifier", "about", classifiernumber);
824 disp.setmacro ("aboutCollage", "about", "_collageapplet_");
825 collage = true;
826 }
827 ++here;
828 }
829 if (! collage)
830 disp.setmacro ("aboutCollage", "about", "_collageempty_");
831
832 // ********************************
833
834 here = response.docInfo.begin();
835
836 while (here != end) {
837
838 text_t title = (*here).metadata["Title"].values[0];
839
840 text_t stext;
841 disp.expandstring ("help", "_text" + title + "help_", stext);
842 if (stext == ("_text" + title + "help_")) {
843 text_t ltext, ttext;
844 disp.expandstring("Global", "_label"+title+"_", ltext);
845 if (ltext == ("_label"+title+"_")) {
846 ltext = title;
847 }
848 disp.expandstring("Global", "_text"+title+"_", ttext);
849 if (ttext == ("_text"+title+"_")) {
850 ttext = title;
851 }
852 helptext += "<li>_help:textdefaulthelp_("+ttext+","+ltext+")";
853 } else {
854 helptext += "<li>_help:text" + title + "help_";
855 }
856
857 ++here;
858 }
859 helptext += "</ul>\n";
860 disp.setmacro ("textbrowseoptions", "help", helptext);
861
862 if (arg_p == "help") {
863 // do we need to add in the datesearch help??
864 text_tmap::iterator check = cinfo->format.find("QueryInterface");
865 if(check != cinfo->format.end()){
866 if((*check).second=="DateSearch"){
867 text_t current = "_datesearch_";
868 disp.setmacro("optdatesearchhelp","help","_datesearchhelp_");
869 disp.setmacro("optdatesearchhelpcontents","help","_datesearchhelpcontents_");
870 }
871 }
872
873 }
874
875 if (arg_p == "about") {
876
877 // _textsubcollections_
878 if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
879 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
880 text_tarray::const_iterator here = cinfo->ccsCols.begin();
881 text_tarray::const_iterator end = cinfo->ccsCols.end();
882 bool first = true;
883 int count = 0;
884 while (here != end) {
885 if (*here == arg_c) {
886 if (!first) textsubcollections += "<br>";
887 textsubcollections += "\n" + cinfo->get_collectionmeta("collectionname", args["l"]) + "\n";
888 } else {
889 ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
890 if (this_cinfo == NULL) {++here; continue;}
891 if (!first) textsubcollections += "<br>";
892 textsubcollections += "\n" + this_cinfo->get_collectionmeta("collectionname", args["l"]) + "\n";
893 }
894 ++count;
895 first = false;
896 ++here;
897 }
898 textsubcollections += "_textsubcols2_";
899 if (count > 1) {
900 disp.setmacro ("textsubcollections", "about", textsubcollections);
901 }
902 }
903
904 comerror_t err;
905 bool issearchable = true;
906 collectproto->is_searchable(args["c"], issearchable, err, logout);
907 if (err != noError) issearchable = true;
908 outconvertclass t;
909 if (!issearchable ) {
910 disp.setmacro ("aboutqueryform", "about", "");
911 }
912 }
913
914 } else if (arg_p == "docs") {
915
916 set_documentation_macro (disp);
917
918 } else if (arg_p == "bsummary" && !arg_c.empty()) {
919
920 set_macro_to_file_contents (disp, "importlog", "bsummary",
921 filename_cat(gsdlhome, "collect", arg_c, "etc", "import.log"));
922 set_macro_to_file_contents (disp, "faillog", "bsummary",
923 filename_cat(gsdlhome, "collect", arg_c, "etc", "fail.log"));
924 set_macro_to_file_contents (disp, "buildlog", "bsummary",
925 filename_cat(gsdlhome, "collect", arg_c, "etc", "build.log"));
926 }
927}
928
929bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
930 browsermapclass * /*browsers*/, displayclass &disp,
931 outconvertclass &outconvert, ostream &textout,
932 ostream &/*logout*/) {
933
934 text_t &arg_p = args["p"];
935
936 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
937 << ("_" + arg_p + ":content_\n")
938 << ("_" + arg_p + ":footer_\n");
939
940 return true;
941}
942
943void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
944 if ((key == "status") && (cfgline.size() == 1) &&
945 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
946 status_disabled = false;
947 } else if ((key == "collector") && (cfgline.size() == 1) &&
948 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
949 collector_disabled = false;
950 }
951 else if ((key == "depositor") && (cfgline.size() == 1) &&
952 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
953 depositor_disabled = false;
954 }
955 else if ((key == "translator") && (cfgline.size() == 1) &&
956 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
957 translator_disabled = false;
958 } else if ((key == "gliapplet") && (cfgline.size() == 1) &&
959 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
960 gliapplet_disabled = false;
961 }
962 else {
963 // call the parent class to deal with the things which
964 // are not dealt with here
965 action::configure (key, cfgline);
966 }
967}
968
969
970
971
972
973
974
975
976
977
Note: See TracBrowser for help on using the repository browser.