[160] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * pageaction.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[533] | 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.
|
---|
[160] | 9 | *
|
---|
[533] | 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 | *
|
---|
[160] | 24 | *********************************************************************/
|
---|
| 25 |
|
---|
[471] | 26 | #include "OIDtools.h"
|
---|
[160] | 27 | #include "pageaction.h"
|
---|
[172] | 28 | #include "receptionist.h"
|
---|
[2767] | 29 | #include "fileutil.h"
|
---|
[2785] | 30 | #include "gsdltools.h"
|
---|
[284] | 31 | #include <time.h>
|
---|
[160] | 32 |
|
---|
[284] | 33 | pageaction::pageaction () {
|
---|
[160] | 34 |
|
---|
[1759] | 35 | status_disabled = true;
|
---|
| 36 | collector_disabled = true;
|
---|
[3774] | 37 | translator_disabled = true;
|
---|
[284] | 38 | recpt = NULL;
|
---|
| 39 |
|
---|
[452] | 40 | // this action uses cgi variables "a", "p", and "hp"
|
---|
[160] | 41 | cgiarginfo arg_ainfo;
|
---|
| 42 | arg_ainfo.shortname = "a";
|
---|
| 43 | arg_ainfo.longname = "action";
|
---|
| 44 | arg_ainfo.multiplechar = true;
|
---|
| 45 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[165] | 46 | arg_ainfo.argdefault = "p";
|
---|
[160] | 47 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 48 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 49 |
|
---|
| 50 | arg_ainfo.shortname = "p";
|
---|
| 51 | arg_ainfo.longname = "page";
|
---|
| 52 | arg_ainfo.multiplechar = true;
|
---|
| 53 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[771] | 54 | arg_ainfo.argdefault = "home";
|
---|
[511] | 55 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
[160] | 56 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[452] | 57 |
|
---|
| 58 | arg_ainfo.shortname = "hp";
|
---|
| 59 | arg_ainfo.longname = "html page";
|
---|
| 60 | arg_ainfo.multiplechar = true;
|
---|
| 61 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 62 | arg_ainfo.argdefault = "";
|
---|
| 63 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 64 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[2415] | 65 |
|
---|
| 66 | arg_ainfo.shortname = "bp";
|
---|
| 67 | arg_ainfo.longname = "set preferences button";
|
---|
| 68 | arg_ainfo.multiplechar = true;
|
---|
| 69 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 70 | arg_ainfo.argdefault = "";
|
---|
| 71 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 72 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[2664] | 73 |
|
---|
| 74 | // the "u" argument will disable the search facility, remove links to the
|
---|
| 75 | // home and preferences pages, and disable the DocumentButton buttons
|
---|
| 76 | // (for use when generating static html versions of collections)
|
---|
| 77 | arg_ainfo.shortname = "u";
|
---|
| 78 | arg_ainfo.longname = "static page";
|
---|
| 79 | arg_ainfo.multiplechar = false;
|
---|
| 80 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 81 | arg_ainfo.argdefault = "0";
|
---|
| 82 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 83 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[160] | 84 | }
|
---|
| 85 |
|
---|
| 86 | pageaction::~pageaction () {
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[2415] | 89 | bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args,
|
---|
[3546] | 90 | recptprotolistclass * /*protos*/, ostream &/*logout*/) {
|
---|
[2415] | 91 |
|
---|
| 92 | if (args["p"] == "preferences" && !args["bp"].empty()) {
|
---|
| 93 | if (args["hd"] != "0") args["hd"] = args["hdn"];
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[160] | 96 | return true;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[761] | 99 | void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
| 100 | response_t &response,text_t &response_data,
|
---|
| 101 | ostream &/*logout*/) {
|
---|
[160] | 102 | response = content;
|
---|
| 103 | response_data = "text/html";
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[761] | 106 | void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
|
---|
[2945] | 107 | cgiargsclass &args, ostream &logout) {
|
---|
[761] | 108 | text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
|
---|
[1276] | 109 | bool found_valid_col = false;
|
---|
[761] | 110 |
|
---|
| 111 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
| 112 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
| 113 | while (rprotolist_here != rprotolist_end) {
|
---|
| 114 | if ((*rprotolist_here).p != NULL) {
|
---|
| 115 |
|
---|
| 116 | text_tarray collist;
|
---|
| 117 | comerror_t err;
|
---|
| 118 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
| 119 | if (err == noError) {
|
---|
| 120 | text_tarray::iterator collist_here = collist.begin();
|
---|
| 121 | text_tarray::iterator collist_end = collist.end();
|
---|
[1247] | 122 |
|
---|
| 123 | int count = 0;
|
---|
| 124 | bool first = true;
|
---|
[761] | 125 | while (collist_here != collist_end) {
|
---|
[1270] | 126 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
|
---|
[761] | 127 |
|
---|
[1270] | 128 | if (cinfo != NULL) {
|
---|
| 129 | if (cinfo->isPublic && (cinfo->buildDate > 0)) {
|
---|
[1912] | 130 |
|
---|
| 131 | text_t coll_type = "&ct=";
|
---|
| 132 | if (cinfo->buildType == "mgpp") {
|
---|
| 133 | coll_type += "1";
|
---|
| 134 | }
|
---|
| 135 | else {
|
---|
| 136 | coll_type += "0";
|
---|
| 137 | }
|
---|
[1276] | 138 | found_valid_col = true;
|
---|
[1860] | 139 | FilterResponse_t response;
|
---|
[761] | 140 | text_tset metadata;
|
---|
| 141 | metadata.insert ("collectionname");
|
---|
| 142 | metadata.insert ("iconcollection");
|
---|
| 143 | metadata.insert ("iconcollectionsmall");
|
---|
| 144 | text_t collectionname = *collist_here;
|
---|
| 145 | text_t alt = collectionname;
|
---|
[1860] | 146 |
|
---|
[761] | 147 | if (get_info ("collection", *collist_here, metadata, false,
|
---|
| 148 | (*rprotolist_here).p, response, logout)) {
|
---|
| 149 | if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
|
---|
| 150 | alt = response.docInfo[0].metadata["collectionname"].values[0];
|
---|
| 151 |
|
---|
[1860] | 152 | text_t iconurl;
|
---|
| 153 | iconurl.clear();
|
---|
| 154 |
|
---|
[1877] | 155 | if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty()) {
|
---|
| 156 | iconurl = response.docInfo[0].metadata["iconcollectionsmall"].values[0];
|
---|
| 157 | } else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty()) {
|
---|
| 158 | iconurl = response.docInfo[0].metadata["iconcollection"].values[0];
|
---|
| 159 | }
|
---|
[1860] | 160 |
|
---|
| 161 | if (!iconurl.empty())
|
---|
| 162 | {
|
---|
| 163 | // check to see URL is local to colserver
|
---|
| 164 | text_t::iterator iconurl_head = iconurl.begin();
|
---|
| 165 | text_t iconhead = substr(iconurl_head,iconurl_head+16);
|
---|
| 166 | if (iconhead=="_httpcollection_")
|
---|
| 167 | {
|
---|
| 168 | // local and using _httpcollection_
|
---|
| 169 | text_t icontail = substr(iconurl_head+16,iconurl.end());
|
---|
| 170 | iconurl = "http://" + cinfo->httpdomain
|
---|
| 171 | + cinfo->httpprefix + "/collect/"
|
---|
| 172 | + *collist_here + "/" + icontail;
|
---|
| 173 | }
|
---|
| 174 | else if (iconurl[0]=='/')
|
---|
| 175 | {
|
---|
| 176 | // local but with full path
|
---|
| 177 | iconurl = "http://" + cinfo->httpdomain + iconurl;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | collectionname
|
---|
| 181 | = "<img width=150 border=1 src=\"" + iconurl + "\" alt=\"" + alt + "\">";
|
---|
| 182 | }
|
---|
| 183 | else
|
---|
| 184 | {
|
---|
| 185 | collectionname = alt;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[761] | 188 | }
|
---|
[1247] | 189 | if ((count%3 == 0) && (!first))
|
---|
| 190 | homeextra += "</tr><tr valign=top>\n";
|
---|
[970] | 191 |
|
---|
[2113] | 192 | comerror_t err;
|
---|
[1860] | 193 | text_t optsite = "";
|
---|
[2113] | 194 | text_t site_name = (*rprotolist_here).p->get_site_name (err);
|
---|
[1860] | 195 | if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
|
---|
| 196 |
|
---|
[2945] | 197 | text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type;
|
---|
| 198 | link += "&l=" + args["l"] + "&w=" + args["w"] + "\">";
|
---|
[761] | 199 |
|
---|
[1270] | 200 | if (!cinfo->receptionist.empty())
|
---|
| 201 | link = "<a href=\"" + cinfo->receptionist + "\">";
|
---|
[761] | 202 |
|
---|
[1247] | 203 | homeextra += "<td>" + link + collectionname + "</a></td>\n";
|
---|
[761] | 204 |
|
---|
| 205 | count ++;
|
---|
[1247] | 206 | first = false;
|
---|
[761] | 207 | }
|
---|
| 208 | }
|
---|
| 209 | collist_here ++;
|
---|
| 210 | }
|
---|
[1347] | 211 |
|
---|
[1247] | 212 | for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
|
---|
[761] | 213 | }
|
---|
| 214 | }
|
---|
[1347] | 215 | homeextra += "</td></tr>\n<tr>\n";
|
---|
[761] | 216 | rprotolist_here ++;
|
---|
| 217 | }
|
---|
[1276] | 218 |
|
---|
| 219 | if (!found_valid_col) {
|
---|
| 220 | homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
|
---|
| 221 | }
|
---|
| 222 | homeextra += "</tr></table></center>\n";
|
---|
| 223 | disp.setmacro ("homeextra", "home", homeextra);
|
---|
[761] | 224 | }
|
---|
| 225 |
|
---|
[2329] | 226 | void pageaction::set_collectionlist_macro (displayclass &disp, recptprotolistclass *protos,
|
---|
| 227 | ostream &logout) {
|
---|
| 228 |
|
---|
| 229 | text_t collectionlist;
|
---|
| 230 | int count = 0;
|
---|
| 231 |
|
---|
| 232 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
| 233 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
| 234 | while (rprotolist_here != rprotolist_end) {
|
---|
| 235 | if ((*rprotolist_here).p != NULL) {
|
---|
| 236 |
|
---|
| 237 | text_tarray collist;
|
---|
| 238 | comerror_t err;
|
---|
| 239 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
| 240 | if (err == noError) {
|
---|
| 241 | text_tarray::iterator collist_here = collist.begin();
|
---|
| 242 | text_tarray::iterator collist_end = collist.end();
|
---|
| 243 |
|
---|
| 244 | while (collist_here != collist_end) {
|
---|
| 245 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
|
---|
| 246 |
|
---|
| 247 | if (cinfo != NULL) {
|
---|
| 248 | if (cinfo->isPublic && (cinfo->buildDate > 0)) {
|
---|
| 249 |
|
---|
| 250 | count ++;
|
---|
| 251 |
|
---|
| 252 | text_t coll_type = "&ct=";
|
---|
| 253 | if (cinfo->buildType == "mgpp") {
|
---|
| 254 | coll_type += "1";
|
---|
| 255 | }
|
---|
| 256 | else {
|
---|
| 257 | coll_type += "0";
|
---|
| 258 | }
|
---|
| 259 | FilterResponse_t response;
|
---|
| 260 | text_tset metadata;
|
---|
| 261 | metadata.insert ("collectionname");
|
---|
| 262 | text_t collectionname = *collist_here;
|
---|
| 263 |
|
---|
| 264 | if (get_info ("collection", *collist_here, metadata, false,
|
---|
| 265 | (*rprotolist_here).p, response, logout)) {
|
---|
| 266 | if (!response.docInfo[0].metadata["collectionname"].values[0].empty()) {
|
---|
| 267 | collectionname = response.docInfo[0].metadata["collectionname"].values[0];
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | comerror_t err;
|
---|
| 272 | text_t optsite = "";
|
---|
| 273 | text_t site_name = (*rprotolist_here).p->get_site_name (err);
|
---|
| 274 | if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
|
---|
| 275 |
|
---|
| 276 | text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + coll_type+"\">";
|
---|
| 277 |
|
---|
| 278 | if (!cinfo->receptionist.empty())
|
---|
| 279 | link = "<a href=\"" + cinfo->receptionist + "\">";
|
---|
| 280 |
|
---|
| 281 | collectionlist += "<li>" + link + collectionname + "</a>\n";
|
---|
| 282 | }
|
---|
| 283 | }
|
---|
| 284 | collist_here ++;
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 | rprotolist_here ++;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | if (count == 1) {
|
---|
[3047] | 292 | collectionlist = "<p>_text1coll_\n<ul>" +
|
---|
[2329] | 293 | collectionlist + "</ul>\n";
|
---|
| 294 | } else if (count > 1) {
|
---|
[3047] | 295 | collectionlist = "<p>_textmorecolls_(" + text_t(count) +
|
---|
| 296 | ")\n<ul>" + collectionlist + "</ul>\n";
|
---|
[2329] | 297 | }
|
---|
| 298 |
|
---|
| 299 | disp.setmacro ("collectionlist", "homehelp", collectionlist);
|
---|
| 300 | }
|
---|
| 301 |
|
---|
[2767] | 302 | void pageaction::set_documentation_macro (displayclass &disp) {
|
---|
| 303 |
|
---|
| 304 | text_t documentation;
|
---|
| 305 | text_t docsdir = filename_cat(gsdlhome, "docs");
|
---|
| 306 |
|
---|
| 307 | if (file_exists(filename_cat(docsdir, "User.pdf"))) {
|
---|
| 308 | documentation += "<tr valign=middle><td><a href=\"_httpdocs_/User.pdf\">_iconpdf_"
|
---|
| 309 | "</a></td><td>_textuserguide_</td></tr>";
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | if (file_exists(filename_cat(docsdir, "Install.pdf"))) {
|
---|
| 313 | documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Install.pdf\">_iconpdf_"
|
---|
| 314 | "</a></td><td>_textinstallerguide_</td></tr>";
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | if (file_exists(filename_cat(docsdir, "Develop.pdf"))) {
|
---|
| 318 | documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Develop.pdf\">_iconpdf_"
|
---|
| 319 | "</a></td><td>_textdeveloperguide_</td></tr>";
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | if (file_exists(filename_cat(docsdir, "Paper.pdf"))) {
|
---|
| 323 | documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Paper.pdf\">_iconpdf_"
|
---|
| 324 | "</a></td><td>_textpaperguide_</td></tr>";
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | if (!documentation.empty()) {
|
---|
| 328 | disp.setmacro("documentation", "docs", "<p>\n<table border=0>\n" + documentation + "\n</table>\n");
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[2785] | 332 | void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t ¯oname,
|
---|
| 333 | const text_t &packagename, const text_t &filename) {
|
---|
| 334 |
|
---|
| 335 | text_t filecontent;
|
---|
| 336 | char *filenamec = filename.getcstr();
|
---|
| 337 | ifstream file_in (filenamec);
|
---|
| 338 | delete filenamec;
|
---|
| 339 | if (file_in) {
|
---|
| 340 | char c;
|
---|
| 341 | file_in.get(c);
|
---|
| 342 | while (!file_in.eof ()) {
|
---|
| 343 | if (c == '\n') filecontent += "<br>";
|
---|
| 344 | filecontent.push_back(c);
|
---|
| 345 | file_in.get(c);
|
---|
| 346 | }
|
---|
| 347 | file_in.close();
|
---|
| 348 | }
|
---|
| 349 | disp.setmacro (macroname, packagename, dm_safe(filecontent));
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[3625] | 352 | void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
|
---|
| 353 | recptprotolistclass *protos, ColInfoResponse_t *cinfo,
|
---|
| 354 | ostream &logout) {
|
---|
| 355 | // _languageoption_
|
---|
| 356 | // Create the "interface language" selection box for the preferences
|
---|
| 357 | // pages. You can use something like "format PreferenceLanguages
|
---|
| 358 | // en|fr|zn" from within a collect.cfg file to use only a subset of
|
---|
| 359 | // the available languages for any given collection (for
|
---|
| 360 | // collection-specific preferences pages). This facility is kind of
|
---|
| 361 | // ugly though and should be replaced by something better when the
|
---|
| 362 | // configuration files are tidied up (as should all the other
|
---|
| 363 | // "format Preference..." options).
|
---|
| 364 | text_t &arg_l = args["l"];
|
---|
| 365 | const recptconf &configinfo = recpt->get_configinfo();
|
---|
| 366 | // put languages in another map to sort them by longname
|
---|
| 367 | text_tmap languages;
|
---|
| 368 | languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
|
---|
| 369 | languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
|
---|
| 370 | while (thislang != endlang) {
|
---|
| 371 | languages[(*thislang).second.longname] = (*thislang).first;
|
---|
| 372 | thislang++;
|
---|
| 373 | }
|
---|
| 374 | text_tmap::iterator tlang = languages.begin();
|
---|
| 375 | text_tmap::iterator elang = languages.end();
|
---|
| 376 |
|
---|
| 377 | text_t languageoption;
|
---|
| 378 | bool collection_specific = false;
|
---|
| 379 |
|
---|
| 380 | if (cinfo != NULL) {
|
---|
| 381 | text_tmap::const_iterator it = cinfo->format.find ("PreferenceLanguages");
|
---|
| 382 | if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
|
---|
| 383 | collection_specific = true;
|
---|
| 384 | text_tset pref_langs;
|
---|
| 385 | splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
|
---|
| 386 | if (pref_langs.size() > 1) {
|
---|
| 387 | while (tlang != elang) {
|
---|
| 388 | if (pref_langs.find((*tlang).second) != pref_langs.end()) {
|
---|
| 389 | languageoption += "<option value=\"" + (*tlang).second + "\"";
|
---|
| 390 | if ((*tlang).second == arg_l) languageoption += " selected";
|
---|
| 391 | languageoption += ">" + (*tlang).first + "\n";
|
---|
| 392 | }
|
---|
| 393 | tlang ++;
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | if (!collection_specific) {
|
---|
| 400 | while (tlang != elang) {
|
---|
| 401 | languageoption += "<option value=\"" + (*tlang).second + "\"";
|
---|
| 402 | if ((*tlang).second == arg_l) languageoption += " selected";
|
---|
| 403 | languageoption += ">" + (*tlang).first + "\n";
|
---|
| 404 | tlang ++;
|
---|
| 405 | }
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | if (!languageoption.empty()) {
|
---|
| 409 | languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
|
---|
| 410 | languageoption += "</select>\n";
|
---|
| 411 | disp.setmacro ("languageoption", args["p"], languageoption);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | // _encodingoption_
|
---|
| 415 | // create the "encoding" selection box for the preferences page
|
---|
| 416 | if (configinfo.encodings.size() > 1) {
|
---|
| 417 | text_t &arg_w = args["w"];
|
---|
| 418 | text_t encodingoption;
|
---|
| 419 | text_tmap::const_iterator thisenc = configinfo.encodings.begin();
|
---|
| 420 | text_tmap::const_iterator endenc = configinfo.encodings.end();
|
---|
| 421 | while (thisenc != endenc) {
|
---|
| 422 | encodingoption += "<option value=\"" + (*thisenc).second + "\"";
|
---|
| 423 | if ((*thisenc).second == arg_w) encodingoption += " selected";
|
---|
| 424 | encodingoption += ">" + (*thisenc).first + "\n";
|
---|
| 425 | thisenc ++;
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
|
---|
| 429 | encodingoption += "</select>\n";
|
---|
| 430 | disp.setmacro ("encodingoption", args["p"], encodingoption);
|
---|
| 431 | }
|
---|
| 432 | }
|
---|
| 433 |
|
---|
[761] | 434 | void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
| 435 | recptprotolistclass *protos, ostream &logout) {
|
---|
| 436 |
|
---|
[284] | 437 | // define_internal_macros sets the following macros:
|
---|
| 438 |
|
---|
[866] | 439 | // _numdocs_ the number of documents in the collection
|
---|
| 440 |
|
---|
| 441 | // _builddate_ the date last built
|
---|
| 442 |
|
---|
[471] | 443 | // if page is "home"
|
---|
| 444 | // _homeextra_ this is the list of available collections and collection info
|
---|
| 445 | // to be displayed on the home page
|
---|
[284] | 446 |
|
---|
[471] | 447 |
|
---|
[866] | 448 | // if page is "preferences"
|
---|
| 449 | // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
|
---|
| 450 |
|
---|
| 451 | // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
|
---|
| 452 |
|
---|
[867] | 453 | // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
|
---|
[866] | 454 |
|
---|
[3625] | 455 |
|
---|
| 456 | // if page is "preferences" or "homepref"
|
---|
[867] | 457 | // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
|
---|
| 458 |
|
---|
[1856] | 459 | // _encodingoption_ encodings to select from
|
---|
[867] | 460 |
|
---|
[3625] | 461 |
|
---|
[471] | 462 | // if page is "about"
|
---|
[866] | 463 | // _textsubcollections_ the text on which subcollections make up the collection (if
|
---|
| 464 | // cross-collection searching is being used
|
---|
[471] | 465 |
|
---|
| 466 | // _textbrowseoptions_ the 'how to find information' text in the about and help pages
|
---|
| 467 |
|
---|
| 468 | // _numbrowseoptions_ the number of browsing options
|
---|
| 469 |
|
---|
[2415] | 470 | // _prefschanged_ will be set to _textprefschanged_ if the "set preferences" button
|
---|
| 471 | // was pressed
|
---|
[471] | 472 |
|
---|
[2415] | 473 |
|
---|
[471] | 474 | // if page is "help"
|
---|
| 475 | // _textbrowseoptions_ the 'how to find information' text in the about and help pages
|
---|
| 476 |
|
---|
| 477 | // _numbrowseoptions_ the number of browsing options
|
---|
| 478 |
|
---|
[875] | 479 | // _topicreadingdocs_ this section of the help text differs depending on what type of
|
---|
| 480 | // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
|
---|
| 481 | // _texthelpreadingdocs_
|
---|
| 482 |
|
---|
[1759] | 483 | // _textgocollector_ set to "" if collector is disabled in main.cfg
|
---|
| 484 | // _textgoadmin_ set to "" if status is disabled in main.cfg
|
---|
[3774] | 485 | // _textgotranslator_ set to "" if translator is disabled in main.cfg
|
---|
[1759] | 486 |
|
---|
[2329] | 487 |
|
---|
| 488 | // if page is "homehelp"
|
---|
| 489 | // _collectionlist_ list of available collections to be displayed on the homehelp page
|
---|
[2767] | 490 |
|
---|
[471] | 491 |
|
---|
[2767] | 492 | // if page is "docs"
|
---|
| 493 | // _documentation_ links to PDF documents if they're available
|
---|
| 494 |
|
---|
[2785] | 495 |
|
---|
| 496 | // if page is "bsummary"
|
---|
| 497 | // _importlog_ set to contents of collections import.log file
|
---|
| 498 | // _faillog_ set to contents of collections fail.log file
|
---|
| 499 |
|
---|
[2767] | 500 |
|
---|
[1270] | 501 | if (recpt == NULL) {
|
---|
| 502 | logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
|
---|
| 503 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
| 504 | << " probably not called from the module which instantiated this action.\n";
|
---|
| 505 | return;
|
---|
| 506 | }
|
---|
| 507 |
|
---|
[471] | 508 | text_t &arg_p = args["p"];
|
---|
[866] | 509 | text_t &arg_c = args["c"];
|
---|
[1270] | 510 | ColInfoResponse_t *cinfo = NULL;
|
---|
[471] | 511 |
|
---|
[866] | 512 | recptproto* collectproto = protos->getrecptproto (arg_c, logout);
|
---|
[793] | 513 | if (collectproto != NULL) {
|
---|
[1270] | 514 | cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
|
---|
[2370] | 515 |
|
---|
[1270] | 516 | disp.setmacro ("numdocs", "Global", cinfo->numDocs);
|
---|
[793] | 517 | unsigned long current_time = time(NULL);
|
---|
[1270] | 518 | unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
|
---|
[793] | 519 | disp.setmacro ("builddate", "Global", builddate);
|
---|
[2370] | 520 |
|
---|
| 521 | text_t numbytes;
|
---|
| 522 | if ((cinfo->numBytes/(1024*1024)) > 1) {
|
---|
| 523 | numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
|
---|
| 524 | } else if ((cinfo->numBytes/1024) > 1) {
|
---|
| 525 | numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
|
---|
| 526 | } else {
|
---|
| 527 | numbytes = (text_t)cinfo->numBytes + " bytes";
|
---|
| 528 | }
|
---|
| 529 | disp.setmacro("numbytes", "Global", numbytes);
|
---|
[793] | 530 | }
|
---|
[2782] | 531 |
|
---|
| 532 | //setting _queryformcontent_ so that the query interface is consistent.
|
---|
| 533 | if(arg_p == "about"){
|
---|
[2785] | 534 | if (cinfo != NULL) {
|
---|
| 535 | text_tmap::iterator check = cinfo->format.find("QueryInterface");
|
---|
| 536 | if(check != cinfo->format.end()){
|
---|
| 537 | if((*check).second=="DateSearch"){
|
---|
| 538 | text_t current = "_basicqueryform_ _datesearch_";
|
---|
[2782] | 539 |
|
---|
[2785] | 540 | disp.setmacro("queryformcontent","query",current);
|
---|
| 541 | }
|
---|
[2782] | 542 | }
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
[793] | 545 |
|
---|
[1759] | 546 | if (arg_p == "home") {
|
---|
[2945] | 547 | set_homeextra_macro (disp, protos, args, logout);
|
---|
[1759] | 548 | if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
|
---|
| 549 | if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
|
---|
[3774] | 550 | if (translator_disabled) disp.setmacro ("textgotranslator", "home", "");
|
---|
[3625] | 551 |
|
---|
| 552 | } else if (arg_p == "homepref") {
|
---|
[2782] | 553 |
|
---|
[3625] | 554 | // set _languageoption_ and _encodingoption_
|
---|
| 555 | set_language_encoding_macros(disp, args, protos, cinfo, logout);
|
---|
| 556 |
|
---|
| 557 | } else if (arg_p == "preferences") {
|
---|
[2105] | 558 | if (collectproto == NULL) {return;}
|
---|
[3625] | 559 |
|
---|
| 560 | // set _languageoption_ and _encodingoption_
|
---|
| 561 | set_language_encoding_macros(disp, args, protos, cinfo, logout);
|
---|
| 562 |
|
---|
[866] | 563 | // _collectionoption_
|
---|
| 564 |
|
---|
[2785] | 565 | if ((args["ccs"] == "1") && (cinfo->ccsCols.size() > 1)) {
|
---|
[866] | 566 | text_t collectionoption = "_textcollectionoption_";
|
---|
[1270] | 567 | text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
|
---|
| 568 | text_tarray::const_iterator col_end = cinfo->ccsCols.end();
|
---|
[905] | 569 | int count = 0;
|
---|
[866] | 570 | while (col_here != col_end) {
|
---|
| 571 | text_t colname;
|
---|
| 572 | if (*col_here == arg_c) {
|
---|
[1270] | 573 | colname = cinfo->collectionmeta["collectionname"];
|
---|
[866] | 574 | } else {
|
---|
[1270] | 575 | ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
|
---|
| 576 | if (this_cinfo == NULL) {col_here ++; continue;}
|
---|
| 577 | colname = this_cinfo->collectionmeta["collectionname"];
|
---|
[866] | 578 | }
|
---|
| 579 |
|
---|
[905] | 580 | count ++;
|
---|
[866] | 581 | collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
|
---|
| 582 | *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
|
---|
| 583 | colname + "<br>\n";
|
---|
| 584 | col_here ++;
|
---|
| 585 | }
|
---|
[905] | 586 |
|
---|
| 587 | if (count > 1)
|
---|
| 588 | disp.setmacro ("collectionoption", "preferences", collectionoption);
|
---|
[866] | 589 | }
|
---|
| 590 |
|
---|
| 591 | // _htmloptions_
|
---|
| 592 |
|
---|
[1270] | 593 | text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
|
---|
| 594 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
[866] | 595 | disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
|
---|
| 596 |
|
---|
[867] | 597 |
|
---|
| 598 | // _PreferenceDocsFromWeb_
|
---|
| 599 |
|
---|
[1270] | 600 | it = cinfo->format.find ("PreferenceDocsFromWeb");
|
---|
| 601 | if ((it == cinfo->format.end()) || ((*it).second == "true"))
|
---|
[867] | 602 | disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
|
---|
| 603 | }
|
---|
| 604 |
|
---|
[2415] | 605 | // _prefschanged_
|
---|
| 606 | if (!args["bp"].empty()) {
|
---|
| 607 | disp.setmacro ("prefschanged", "preferences", "_textprefschanged_");
|
---|
| 608 | }
|
---|
[867] | 609 |
|
---|
[866] | 610 | } else if (arg_p == "about" || arg_p == "help") {
|
---|
[761] | 611 | if (collectproto == NULL) return;
|
---|
| 612 |
|
---|
[471] | 613 | // _textbrowseoptions_ and _numbrowseoptions_
|
---|
[761] | 614 |
|
---|
[471] | 615 | FilterResponse_t response;
|
---|
[649] | 616 | text_tset metadata;
|
---|
| 617 | metadata.insert ("Title");
|
---|
[471] | 618 | bool getParents = false;
|
---|
| 619 | get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
|
---|
| 620 |
|
---|
| 621 | disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
|
---|
| 622 |
|
---|
[649] | 623 | ResultDocInfo_tarray::iterator here = response.docInfo.begin();
|
---|
| 624 | ResultDocInfo_tarray::iterator end = response.docInfo.end();
|
---|
[471] | 625 |
|
---|
| 626 | // we're assuming that we've always got a search button
|
---|
| 627 | text_t shorttext = "<ul><li>_textSearchshort_\n";
|
---|
| 628 | text_t longtext = "_textSearchlong_";
|
---|
| 629 |
|
---|
| 630 | while (here != end) {
|
---|
[649] | 631 | text_t title = (*here).metadata["Title"].values[0];
|
---|
[604] | 632 |
|
---|
[649] | 633 | text_t stext, ltext;
|
---|
[729] | 634 | disp.expandstring ("help", "_text" + title + "short_", stext);
|
---|
[649] | 635 | if (stext == ("_text" + title + "short_")) {
|
---|
[729] | 636 | shorttext += "<li>_help:textdefaultshorttext_";
|
---|
| 637 | longtext += "_help:textdefaultlongtext_";
|
---|
[649] | 638 | } else {
|
---|
[1667] | 639 | shorttext += "<li>_help:text" + title + "short_";
|
---|
[729] | 640 | longtext += "_help:text" + title + "long_";
|
---|
[649] | 641 | }
|
---|
[729] | 642 |
|
---|
[471] | 643 | here ++;
|
---|
| 644 | }
|
---|
| 645 | shorttext += "</ul>\n";
|
---|
[867] | 646 | if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
|
---|
| 647 | else disp.setmacro ("textbrowseoptions", "help", longtext);
|
---|
[866] | 648 |
|
---|
[875] | 649 | if (arg_p == "help") {
|
---|
| 650 |
|
---|
| 651 | // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
|
---|
| 652 |
|
---|
| 653 | // if HTML collection there's no how to read document text
|
---|
[1270] | 654 | text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
|
---|
| 655 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
[875] | 656 | disp.setmacro ("topicreadingdocs", "help", "");
|
---|
| 657 | disp.setmacro ("texthelpreadingdocs", "help", "");
|
---|
| 658 | }
|
---|
[1270] | 659 | it = cinfo->format.find ("HelpBibDocs");
|
---|
| 660 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
[875] | 661 | disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
|
---|
| 662 | disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
|
---|
| 663 | }
|
---|
[1270] | 664 | it = cinfo->format.find ("HelpBookDocs");
|
---|
| 665 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
[875] | 666 | disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
|
---|
| 667 | disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
|
---|
| 668 | }
|
---|
| 669 |
|
---|
| 670 | }
|
---|
[866] | 671 | if (arg_p == "about") {
|
---|
| 672 |
|
---|
| 673 | // _textsubcollections_
|
---|
[1270] | 674 | if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
|
---|
| 675 | text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
|
---|
| 676 | text_tarray::const_iterator here = cinfo->ccsCols.begin();
|
---|
| 677 | text_tarray::const_iterator end = cinfo->ccsCols.end();
|
---|
[867] | 678 | bool first = true;
|
---|
[905] | 679 | int count = 0;
|
---|
[866] | 680 | while (here != end) {
|
---|
| 681 | if (*here == arg_c) {
|
---|
[867] | 682 | if (!first) textsubcollections += "<br>";
|
---|
[1270] | 683 | textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
|
---|
[866] | 684 | } else {
|
---|
[1270] | 685 | ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
|
---|
| 686 | if (this_cinfo == NULL) {here ++; continue;}
|
---|
[905] | 687 | if (!first) textsubcollections += "<br>";
|
---|
[1270] | 688 | textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
|
---|
[866] | 689 | }
|
---|
[905] | 690 | count ++;
|
---|
[867] | 691 | first = false;
|
---|
[866] | 692 | here ++;
|
---|
| 693 | }
|
---|
| 694 | textsubcollections += "_textsubcols2_";
|
---|
[905] | 695 | if (count > 1)
|
---|
| 696 | disp.setmacro ("textsubcollections", "about", textsubcollections);
|
---|
[866] | 697 | }
|
---|
| 698 | }
|
---|
[2329] | 699 |
|
---|
| 700 | } else if (arg_p == "homehelp") {
|
---|
| 701 |
|
---|
| 702 | set_collectionlist_macro (disp, protos, logout);
|
---|
| 703 |
|
---|
[2767] | 704 | } else if (arg_p == "docs") {
|
---|
| 705 |
|
---|
| 706 | set_documentation_macro (disp);
|
---|
| 707 |
|
---|
[2785] | 708 | } else if (arg_p == "bsummary" && !arg_c.empty()) {
|
---|
| 709 |
|
---|
| 710 | set_macro_to_file_contents (disp, "importlog", "bsummary",
|
---|
| 711 | filename_cat(gsdlhome, "collect", arg_c, "etc", "import.log"));
|
---|
| 712 | set_macro_to_file_contents (disp, "faillog", "bsummary",
|
---|
| 713 | filename_cat(gsdlhome, "collect", arg_c, "etc", "fail.log"));
|
---|
[471] | 714 | }
|
---|
[284] | 715 | }
|
---|
| 716 |
|
---|
[761] | 717 | bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
|
---|
| 718 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
[421] | 719 | outconvertclass &outconvert, ostream &textout,
|
---|
| 720 | ostream &/*logout*/) {
|
---|
[173] | 721 |
|
---|
[172] | 722 | text_t &arg_p = args["p"];
|
---|
[160] | 723 |
|
---|
[172] | 724 | textout << outconvert << disp << ("_" + arg_p + ":header_\n")
|
---|
[266] | 725 | << ("_" + arg_p + ":content_\n")
|
---|
[172] | 726 | << ("_" + arg_p + ":footer_\n");
|
---|
| 727 |
|
---|
[160] | 728 | return true;
|
---|
| 729 | }
|
---|
[1759] | 730 |
|
---|
| 731 | void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
| 732 | if ((key == "status") && (cfgline.size() == 1) &&
|
---|
| 733 | (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
|
---|
| 734 | status_disabled = false;
|
---|
| 735 | } else if ((key == "collector") && (cfgline.size() == 1) &&
|
---|
| 736 | (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
|
---|
| 737 | collector_disabled = false;
|
---|
[3774] | 738 | } else if ((key == "translator") && (cfgline.size() == 1) &&
|
---|
| 739 | (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
|
---|
| 740 | translator_disabled = false;
|
---|
[1759] | 741 | } else {
|
---|
| 742 | // call the parent class to deal with the things which
|
---|
| 743 | // are not dealt with here
|
---|
| 744 | action::configure (key, cfgline);
|
---|
| 745 | }
|
---|
| 746 | }
|
---|