root/trunk/gsdl/src/recpt/pageaction.cpp @ 11095

Revision 11095, 33.6 KB (checked in by jrm21, 14 years ago)

move border=1 for logos in the collection list from receptionist into style
sheet.

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