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