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