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 | #include "OIDtools.h"
|
---|
27 | #include "pageaction.h"
|
---|
28 | #include "receptionist.h"
|
---|
29 | #include "fileutil.h"
|
---|
30 | #include "gsdltools.h"
|
---|
31 | #include <time.h>
|
---|
32 |
|
---|
33 | pageaction::pageaction () {
|
---|
34 |
|
---|
35 | status_disabled = true;
|
---|
36 | collector_disabled = true;
|
---|
37 | translator_disabled = true;
|
---|
38 | recpt = NULL;
|
---|
39 |
|
---|
40 | // this action uses cgi variables "a", "p", and "hp"
|
---|
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;
|
---|
46 | arg_ainfo.argdefault = "p";
|
---|
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;
|
---|
54 | arg_ainfo.argdefault = "home";
|
---|
55 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
56 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
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);
|
---|
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);
|
---|
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);
|
---|
84 | }
|
---|
85 |
|
---|
86 | pageaction::~pageaction () {
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args,
|
---|
90 | recptprotolistclass * /*protos*/, ostream &/*logout*/) {
|
---|
91 |
|
---|
92 | if (args["p"] == "preferences" && !args["bp"].empty()) {
|
---|
93 | if (args["hd"] != "0") args["hd"] = args["hdn"];
|
---|
94 | }
|
---|
95 |
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 |
|
---|
99 | void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
100 | response_t &response,text_t &response_data,
|
---|
101 | ostream &/*logout*/) {
|
---|
102 | response = content;
|
---|
103 | response_data = "text/html";
|
---|
104 | }
|
---|
105 |
|
---|
106 | void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
|
---|
107 | cgiargsclass &args, ostream &logout) {
|
---|
108 | text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
|
---|
109 | bool found_valid_col = false;
|
---|
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();
|
---|
122 |
|
---|
123 | int count = 0;
|
---|
124 | bool first = true;
|
---|
125 | while (collist_here != collist_end) {
|
---|
126 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
|
---|
127 |
|
---|
128 | if (cinfo != NULL) {
|
---|
129 | if (cinfo->isPublic && (cinfo->buildDate > 0)) {
|
---|
130 |
|
---|
131 | text_t coll_type = "&ct=";
|
---|
132 | if (cinfo->buildType == "mgpp") {
|
---|
133 | coll_type += "1";
|
---|
134 | }
|
---|
135 | else {
|
---|
136 | coll_type += "0";
|
---|
137 | }
|
---|
138 | found_valid_col = true;
|
---|
139 | FilterResponse_t response;
|
---|
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;
|
---|
146 |
|
---|
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 |
|
---|
152 | text_t iconurl;
|
---|
153 | iconurl.clear();
|
---|
154 |
|
---|
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 | }
|
---|
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 |
|
---|
188 | }
|
---|
189 | if ((count%3 == 0) && (!first))
|
---|
190 | homeextra += "</tr><tr valign=top>\n";
|
---|
191 |
|
---|
192 | comerror_t err;
|
---|
193 | text_t optsite = "";
|
---|
194 | text_t site_name = (*rprotolist_here).p->get_site_name (err);
|
---|
195 | if (!site_name.empty()) { optsite = "site="+site_name+"&"; }
|
---|
196 |
|
---|
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"] + "\">";
|
---|
199 |
|
---|
200 | if (!cinfo->receptionist.empty())
|
---|
201 | link = "<a href=\"" + cinfo->receptionist + "\">";
|
---|
202 |
|
---|
203 | homeextra += "<td>" + link + collectionname + "</a></td>\n";
|
---|
204 |
|
---|
205 | count ++;
|
---|
206 | first = false;
|
---|
207 | }
|
---|
208 | }
|
---|
209 | collist_here ++;
|
---|
210 | }
|
---|
211 |
|
---|
212 | for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
|
---|
213 | }
|
---|
214 | }
|
---|
215 | homeextra += "</td></tr>\n<tr>\n";
|
---|
216 | rprotolist_here ++;
|
---|
217 | }
|
---|
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);
|
---|
224 | }
|
---|
225 |
|
---|
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) {
|
---|
292 | collectionlist = "<p>_text1coll_\n<ul>" +
|
---|
293 | collectionlist + "</ul>\n";
|
---|
294 | } else if (count > 1) {
|
---|
295 | collectionlist = "<p>_textmorecolls_(" + text_t(count) +
|
---|
296 | ")\n<ul>" + collectionlist + "</ul>\n";
|
---|
297 | }
|
---|
298 |
|
---|
299 | disp.setmacro ("collectionlist", "homehelp", collectionlist);
|
---|
300 | }
|
---|
301 |
|
---|
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 |
|
---|
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 |
|
---|
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 |
|
---|
434 | void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
435 | recptprotolistclass *protos, ostream &logout) {
|
---|
436 |
|
---|
437 | // define_internal_macros sets the following macros:
|
---|
438 |
|
---|
439 | // _numdocs_ the number of documents in the collection
|
---|
440 |
|
---|
441 | // _builddate_ the date last built
|
---|
442 |
|
---|
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
|
---|
446 |
|
---|
447 |
|
---|
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 |
|
---|
453 | // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
|
---|
454 |
|
---|
455 |
|
---|
456 | // if page is "preferences" or "homepref"
|
---|
457 | // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
|
---|
458 |
|
---|
459 | // _encodingoption_ encodings to select from
|
---|
460 |
|
---|
461 |
|
---|
462 | // if page is "about"
|
---|
463 | // _textsubcollections_ the text on which subcollections make up the collection (if
|
---|
464 | // cross-collection searching is being used
|
---|
465 |
|
---|
466 | // _textbrowseoptions_ the 'how to find information' text in the about and help pages
|
---|
467 |
|
---|
468 | // _numbrowseoptions_ the number of browsing options
|
---|
469 |
|
---|
470 | // _prefschanged_ will be set to _textprefschanged_ if the "set preferences" button
|
---|
471 | // was pressed
|
---|
472 |
|
---|
473 |
|
---|
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 |
|
---|
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 |
|
---|
483 | // if page is "home" or "homehelp"
|
---|
484 | // _textgocollector_ set to "" if collector is disabled in main.cfg
|
---|
485 | // _textgoadmin_ set to "" if status is disabled in main.cfg
|
---|
486 | // _textgotranslator_ set to "" if translator is disabled in main.cfg
|
---|
487 |
|
---|
488 |
|
---|
489 | // if page is "homehelp"
|
---|
490 | // _collectionlist_ list of available collections to be displayed on the homehelp page
|
---|
491 |
|
---|
492 |
|
---|
493 | // if page is "docs"
|
---|
494 | // _documentation_ links to PDF documents if they're available
|
---|
495 |
|
---|
496 |
|
---|
497 | // if page is "bsummary"
|
---|
498 | // _importlog_ set to contents of collections import.log file
|
---|
499 | // _faillog_ set to contents of collections fail.log file
|
---|
500 |
|
---|
501 |
|
---|
502 | if (recpt == NULL) {
|
---|
503 | logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
|
---|
504 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
505 | << " probably not called from the module which instantiated this action.\n";
|
---|
506 | return;
|
---|
507 | }
|
---|
508 |
|
---|
509 | text_t &arg_p = args["p"];
|
---|
510 | text_t &arg_c = args["c"];
|
---|
511 | ColInfoResponse_t *cinfo = NULL;
|
---|
512 |
|
---|
513 | recptproto* collectproto = protos->getrecptproto (arg_c, logout);
|
---|
514 | if (collectproto != NULL) {
|
---|
515 | cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
|
---|
516 |
|
---|
517 | disp.setmacro ("numdocs", "Global", cinfo->numDocs);
|
---|
518 | unsigned long current_time = time(NULL);
|
---|
519 | unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
|
---|
520 | disp.setmacro ("builddate", "Global", builddate);
|
---|
521 |
|
---|
522 | text_t numbytes;
|
---|
523 | if ((cinfo->numBytes/(1024*1024)) > 1) {
|
---|
524 | numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
|
---|
525 | } else if ((cinfo->numBytes/1024) > 1) {
|
---|
526 | numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
|
---|
527 | } else {
|
---|
528 | numbytes = (text_t)cinfo->numBytes + " bytes";
|
---|
529 | }
|
---|
530 | disp.setmacro("numbytes", "Global", numbytes);
|
---|
531 | }
|
---|
532 |
|
---|
533 | //setting _queryformcontent_ so that the query interface is consistent.
|
---|
534 | if(arg_p == "about"){
|
---|
535 | if (cinfo != NULL) {
|
---|
536 | text_tmap::iterator check = cinfo->format.find("QueryInterface");
|
---|
537 | if(check != cinfo->format.end()){
|
---|
538 | if((*check).second=="DateSearch"){
|
---|
539 | text_t current = "_basicqueryform_ _datesearch_";
|
---|
540 |
|
---|
541 | disp.setmacro("queryformcontent","query",current);
|
---|
542 | }
|
---|
543 | }
|
---|
544 | }
|
---|
545 | }
|
---|
546 |
|
---|
547 | if (arg_p == "home" || arg_p == "homehelp") {
|
---|
548 | if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
|
---|
549 | if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
|
---|
550 | if (translator_disabled) disp.setmacro ("textgotranslator", "home", "");
|
---|
551 |
|
---|
552 | if (arg_p == "home") {
|
---|
553 | set_homeextra_macro (disp, protos, args, logout);
|
---|
554 | } else if (arg_p == "homehelp") {
|
---|
555 | set_collectionlist_macro (disp, protos, logout);
|
---|
556 | }
|
---|
557 |
|
---|
558 | } else if (arg_p == "homepref") {
|
---|
559 |
|
---|
560 | // set _languageoption_ and _encodingoption_
|
---|
561 | set_language_encoding_macros(disp, args, protos, cinfo, logout);
|
---|
562 |
|
---|
563 | } else if (arg_p == "preferences") {
|
---|
564 | if (collectproto == NULL) {return;}
|
---|
565 |
|
---|
566 | // set _languageoption_ and _encodingoption_
|
---|
567 | set_language_encoding_macros(disp, args, protos, cinfo, logout);
|
---|
568 |
|
---|
569 | // _collectionoption_
|
---|
570 |
|
---|
571 | if ((args["ccs"] == "1") && (cinfo->ccsCols.size() > 1)) {
|
---|
572 | text_t collectionoption = "_textcollectionoption_";
|
---|
573 | text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
|
---|
574 | text_tarray::const_iterator col_end = cinfo->ccsCols.end();
|
---|
575 | int count = 0;
|
---|
576 | while (col_here != col_end) {
|
---|
577 | text_t colname;
|
---|
578 | if (*col_here == arg_c) {
|
---|
579 | colname = cinfo->collectionmeta["collectionname"];
|
---|
580 | } else {
|
---|
581 | ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
|
---|
582 | if (this_cinfo == NULL) {col_here ++; continue;}
|
---|
583 | colname = this_cinfo->collectionmeta["collectionname"];
|
---|
584 | }
|
---|
585 |
|
---|
586 | count ++;
|
---|
587 | collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
|
---|
588 | *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
|
---|
589 | colname + "<br>\n";
|
---|
590 | col_here ++;
|
---|
591 | }
|
---|
592 |
|
---|
593 | if (count > 1)
|
---|
594 | disp.setmacro ("collectionoption", "preferences", collectionoption);
|
---|
595 | }
|
---|
596 |
|
---|
597 | // _htmloptions_
|
---|
598 |
|
---|
599 | text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
|
---|
600 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
601 | disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
|
---|
602 |
|
---|
603 |
|
---|
604 | // _PreferenceDocsFromWeb_
|
---|
605 |
|
---|
606 | it = cinfo->format.find ("PreferenceDocsFromWeb");
|
---|
607 | if ((it == cinfo->format.end()) || ((*it).second == "true"))
|
---|
608 | disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
|
---|
609 | }
|
---|
610 |
|
---|
611 | // _prefschanged_
|
---|
612 | if (!args["bp"].empty()) {
|
---|
613 | disp.setmacro ("prefschanged", "preferences", "_textprefschanged_");
|
---|
614 | }
|
---|
615 |
|
---|
616 | } else if (arg_p == "about" || arg_p == "help") {
|
---|
617 | if (collectproto == NULL) return;
|
---|
618 |
|
---|
619 | // _textbrowseoptions_ and _numbrowseoptions_
|
---|
620 |
|
---|
621 | FilterResponse_t response;
|
---|
622 | text_tset metadata;
|
---|
623 | metadata.insert ("Title");
|
---|
624 | bool getParents = false;
|
---|
625 | get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
|
---|
626 |
|
---|
627 | disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
|
---|
628 |
|
---|
629 | ResultDocInfo_tarray::iterator here = response.docInfo.begin();
|
---|
630 | ResultDocInfo_tarray::iterator end = response.docInfo.end();
|
---|
631 |
|
---|
632 | // we're assuming that we've always got a search button
|
---|
633 | text_t shorttext = "<ul><li>_textSearchshort_\n";
|
---|
634 | text_t longtext = "_textSearchlong_";
|
---|
635 |
|
---|
636 | while (here != end) {
|
---|
637 | text_t title = (*here).metadata["Title"].values[0];
|
---|
638 |
|
---|
639 | text_t stext, ltext;
|
---|
640 | disp.expandstring ("help", "_text" + title + "short_", stext);
|
---|
641 | if (stext == ("_text" + title + "short_")) {
|
---|
642 | shorttext += "<li>_help:textdefaultshorttext_";
|
---|
643 | longtext += "_help:textdefaultlongtext_";
|
---|
644 | } else {
|
---|
645 | shorttext += "<li>_help:text" + title + "short_";
|
---|
646 | longtext += "_help:text" + title + "long_";
|
---|
647 | }
|
---|
648 |
|
---|
649 | here ++;
|
---|
650 | }
|
---|
651 | shorttext += "</ul>\n";
|
---|
652 | if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
|
---|
653 | else disp.setmacro ("textbrowseoptions", "help", longtext);
|
---|
654 |
|
---|
655 | if (arg_p == "help") {
|
---|
656 |
|
---|
657 | // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
|
---|
658 |
|
---|
659 | // if HTML collection there's no how to read document text
|
---|
660 | text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
|
---|
661 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
662 | disp.setmacro ("topicreadingdocs", "help", "");
|
---|
663 | disp.setmacro ("texthelpreadingdocs", "help", "");
|
---|
664 | }
|
---|
665 | it = cinfo->format.find ("HelpBibDocs");
|
---|
666 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
667 | disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
|
---|
668 | disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
|
---|
669 | }
|
---|
670 | it = cinfo->format.find ("HelpBookDocs");
|
---|
671 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
672 | disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
|
---|
673 | disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
|
---|
674 | }
|
---|
675 |
|
---|
676 | }
|
---|
677 | if (arg_p == "about") {
|
---|
678 |
|
---|
679 | // _textsubcollections_
|
---|
680 | if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
|
---|
681 | text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
|
---|
682 | text_tarray::const_iterator here = cinfo->ccsCols.begin();
|
---|
683 | text_tarray::const_iterator end = cinfo->ccsCols.end();
|
---|
684 | bool first = true;
|
---|
685 | int count = 0;
|
---|
686 | while (here != end) {
|
---|
687 | if (*here == arg_c) {
|
---|
688 | if (!first) textsubcollections += "<br>";
|
---|
689 | textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
|
---|
690 | } else {
|
---|
691 | ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
|
---|
692 | if (this_cinfo == NULL) {here ++; continue;}
|
---|
693 | if (!first) textsubcollections += "<br>";
|
---|
694 | textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
|
---|
695 | }
|
---|
696 | count ++;
|
---|
697 | first = false;
|
---|
698 | here ++;
|
---|
699 | }
|
---|
700 | textsubcollections += "_textsubcols2_";
|
---|
701 | if (count > 1)
|
---|
702 | disp.setmacro ("textsubcollections", "about", textsubcollections);
|
---|
703 | }
|
---|
704 | }
|
---|
705 |
|
---|
706 | } else if (arg_p == "docs") {
|
---|
707 |
|
---|
708 | set_documentation_macro (disp);
|
---|
709 |
|
---|
710 | } else if (arg_p == "bsummary" && !arg_c.empty()) {
|
---|
711 |
|
---|
712 | set_macro_to_file_contents (disp, "importlog", "bsummary",
|
---|
713 | filename_cat(gsdlhome, "collect", arg_c, "etc", "import.log"));
|
---|
714 | set_macro_to_file_contents (disp, "faillog", "bsummary",
|
---|
715 | filename_cat(gsdlhome, "collect", arg_c, "etc", "fail.log"));
|
---|
716 | }
|
---|
717 | }
|
---|
718 |
|
---|
719 | bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
|
---|
720 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
721 | outconvertclass &outconvert, ostream &textout,
|
---|
722 | ostream &/*logout*/) {
|
---|
723 |
|
---|
724 | text_t &arg_p = args["p"];
|
---|
725 |
|
---|
726 | textout << outconvert << disp << ("_" + arg_p + ":header_\n")
|
---|
727 | << ("_" + arg_p + ":content_\n")
|
---|
728 | << ("_" + arg_p + ":footer_\n");
|
---|
729 |
|
---|
730 | return true;
|
---|
731 | }
|
---|
732 |
|
---|
733 | void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
734 | if ((key == "status") && (cfgline.size() == 1) &&
|
---|
735 | (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
|
---|
736 | status_disabled = false;
|
---|
737 | } else if ((key == "collector") && (cfgline.size() == 1) &&
|
---|
738 | (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
|
---|
739 | collector_disabled = false;
|
---|
740 | } else if ((key == "translator") && (cfgline.size() == 1) &&
|
---|
741 | (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
|
---|
742 | translator_disabled = false;
|
---|
743 | } else {
|
---|
744 | // call the parent class to deal with the things which
|
---|
745 | // are not dealt with here
|
---|
746 | action::configure (key, cfgline);
|
---|
747 | }
|
---|
748 | }
|
---|