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