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 <time.h>
|
---|
30 |
|
---|
31 | pageaction::pageaction () {
|
---|
32 |
|
---|
33 | recpt = NULL;
|
---|
34 |
|
---|
35 | // this action uses cgi variables "a", "p", and "hp"
|
---|
36 | cgiarginfo arg_ainfo;
|
---|
37 | arg_ainfo.shortname = "a";
|
---|
38 | arg_ainfo.longname = "action";
|
---|
39 | arg_ainfo.multiplechar = true;
|
---|
40 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
41 | arg_ainfo.argdefault = "p";
|
---|
42 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
43 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
44 |
|
---|
45 | arg_ainfo.shortname = "p";
|
---|
46 | arg_ainfo.longname = "page";
|
---|
47 | arg_ainfo.multiplechar = true;
|
---|
48 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
49 | arg_ainfo.argdefault = "home";
|
---|
50 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
51 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
52 |
|
---|
53 | arg_ainfo.shortname = "hp";
|
---|
54 | arg_ainfo.longname = "html page";
|
---|
55 | arg_ainfo.multiplechar = true;
|
---|
56 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
57 | arg_ainfo.argdefault = "";
|
---|
58 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
59 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
60 | }
|
---|
61 |
|
---|
62 | pageaction::~pageaction () {
|
---|
63 | }
|
---|
64 |
|
---|
65 | bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
|
---|
66 | ostream &/*logout*/) {
|
---|
67 | // don't want to check anything yet.
|
---|
68 | return true;
|
---|
69 | }
|
---|
70 |
|
---|
71 | void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
72 | response_t &response,text_t &response_data,
|
---|
73 | ostream &/*logout*/) {
|
---|
74 | response = content;
|
---|
75 | response_data = "text/html";
|
---|
76 | }
|
---|
77 |
|
---|
78 | void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
|
---|
79 | ostream &logout) {
|
---|
80 |
|
---|
81 | text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
|
---|
82 | bool found_valid_col = false;
|
---|
83 |
|
---|
84 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
85 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
86 | while (rprotolist_here != rprotolist_end) {
|
---|
87 | if ((*rprotolist_here).p != NULL) {
|
---|
88 |
|
---|
89 | text_tarray collist;
|
---|
90 | comerror_t err;
|
---|
91 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
92 | if (err == noError) {
|
---|
93 | text_tarray::iterator collist_here = collist.begin();
|
---|
94 | text_tarray::iterator collist_end = collist.end();
|
---|
95 |
|
---|
96 | int count = 0;
|
---|
97 | bool first = true;
|
---|
98 | while (collist_here != collist_end) {
|
---|
99 |
|
---|
100 | ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
|
---|
101 |
|
---|
102 | if (cinfo != NULL) {
|
---|
103 | if (cinfo->isPublic && (cinfo->buildDate > 0)) {
|
---|
104 |
|
---|
105 | found_valid_col = true;
|
---|
106 | FilterResponse_t response;
|
---|
107 | text_tset metadata;
|
---|
108 | metadata.insert ("collectionname");
|
---|
109 | metadata.insert ("iconcollection");
|
---|
110 | metadata.insert ("iconcollectionsmall");
|
---|
111 | text_t collectionname = *collist_here;
|
---|
112 | text_t alt = collectionname;
|
---|
113 | if (get_info ("collection", *collist_here, metadata, false,
|
---|
114 | (*rprotolist_here).p, response, logout)) {
|
---|
115 | if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
|
---|
116 | alt = response.docInfo[0].metadata["collectionname"].values[0];
|
---|
117 |
|
---|
118 | if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
|
---|
119 | collectionname = "<img width=150 border=1 src=\""
|
---|
120 | + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
|
---|
121 | + "\" alt=\"" + alt + "\">";
|
---|
122 | else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
|
---|
123 | collectionname = "<img width=150 border=1 src=\""
|
---|
124 | + response.docInfo[0].metadata["iconcollection"].values[0]
|
---|
125 | + "\" alt=\"" + alt + "\">";
|
---|
126 | else collectionname = alt;
|
---|
127 | }
|
---|
128 |
|
---|
129 | if ((count%3 == 0) && (!first))
|
---|
130 | homeextra += "</tr><tr valign=top>\n";
|
---|
131 |
|
---|
132 | text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
|
---|
133 | if (*collist_here == "chinese")
|
---|
134 | link = "<a href=\"_gwcgi_?a=p&p=about&l=zh&nw=u&c=" + *collist_here + "\">";
|
---|
135 | if (*collist_here == "arabic")
|
---|
136 | link = "<a href=\"_gwcgi_?a=p&p=about&l=ar&nw=u&c=" + *collist_here + "\">";
|
---|
137 |
|
---|
138 | if (!cinfo->receptionist.empty())
|
---|
139 | link = "<a href=\"" + cinfo->receptionist + "\">";
|
---|
140 |
|
---|
141 | homeextra += "<td>" + link + collectionname + "</a></td>\n";
|
---|
142 |
|
---|
143 | count ++;
|
---|
144 | first = false;
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | collist_here ++;
|
---|
149 | }
|
---|
150 |
|
---|
151 | // disp.setmacro ("homeextra", "home", homeextra);
|
---|
152 | for (; count%3 != 0; count ++) homeextra += "<td></td>\n";
|
---|
153 | }
|
---|
154 | }
|
---|
155 | homeextra += "</td></tr>\n<tr>\n";
|
---|
156 | rprotolist_here ++;
|
---|
157 | }
|
---|
158 |
|
---|
159 | homeextra += "</tr></table></center>\n";
|
---|
160 | disp.setmacro ("homeextra", "home", homeextra);
|
---|
161 |
|
---|
162 | if (!found_valid_col) {
|
---|
163 | homeextra += "<td>No valid (i.e. built and public) collections are available</td>\n";
|
---|
164 | }
|
---|
165 | homeextra += "</tr></table></center>\n";
|
---|
166 | disp.setmacro ("homeextra", "home", homeextra);
|
---|
167 |
|
---|
168 | }
|
---|
169 |
|
---|
170 | void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
171 | recptprotolistclass *protos, ostream &logout) {
|
---|
172 |
|
---|
173 | // define_internal_macros sets the following macros:
|
---|
174 |
|
---|
175 | // _numdocs_ the number of documents in the collection
|
---|
176 |
|
---|
177 | // _builddate_ the date last built
|
---|
178 |
|
---|
179 |
|
---|
180 | // if page is "home"
|
---|
181 | // _homeextra_ this is the list of available collections and collection info
|
---|
182 | // to be displayed on the home page
|
---|
183 |
|
---|
184 |
|
---|
185 | // if page is "preferences"
|
---|
186 | // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
|
---|
187 |
|
---|
188 | // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
|
---|
189 |
|
---|
190 | // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
|
---|
191 |
|
---|
192 | // _languageoption_ interface languages to select from (dependant on PreferenceLanguages)
|
---|
193 |
|
---|
194 | // _encodingoption_ will be overridden to "" if chinese language interface isn't specified
|
---|
195 |
|
---|
196 | // if page is "about"
|
---|
197 | // _textsubcollections_ the text on which subcollections make up the collection (if
|
---|
198 | // cross-collection searching is being used
|
---|
199 |
|
---|
200 | // _textbrowseoptions_ the 'how to find information' text in the about and help pages
|
---|
201 |
|
---|
202 | // _numbrowseoptions_ the number of browsing options
|
---|
203 |
|
---|
204 |
|
---|
205 | // if page is "help"
|
---|
206 | // _textbrowseoptions_ the 'how to find information' text in the about and help pages
|
---|
207 |
|
---|
208 | // _numbrowseoptions_ the number of browsing options
|
---|
209 |
|
---|
210 | // _topicreadingdocs_ this section of the help text differs depending on what type of
|
---|
211 | // _textreadingdocs_ collection it is (e.g. html collection, bibliographic collection etc.)
|
---|
212 | // _texthelpreadingdocs_
|
---|
213 |
|
---|
214 |
|
---|
215 | if (recpt == NULL) {
|
---|
216 | logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
|
---|
217 | << " information about any receptionists. The method set_receptionist was\n"
|
---|
218 | << " probably not called from the module which instantiated this action.\n";
|
---|
219 | return;
|
---|
220 | }
|
---|
221 |
|
---|
222 | text_t &arg_p = args["p"];
|
---|
223 | text_t &arg_c = args["c"];
|
---|
224 | ColInfoResponse_t *cinfo = NULL;
|
---|
225 |
|
---|
226 | recptproto* collectproto = protos->getrecptproto (arg_c, logout);
|
---|
227 | if (collectproto != NULL) {
|
---|
228 | cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
|
---|
229 |
|
---|
230 | disp.setmacro ("numdocs", "Global", cinfo->numDocs);
|
---|
231 | unsigned long current_time = time(NULL);
|
---|
232 | unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
|
---|
233 | disp.setmacro ("builddate", "Global", builddate);
|
---|
234 | }
|
---|
235 |
|
---|
236 | if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
|
---|
237 |
|
---|
238 | else if (arg_p == "preferences") {
|
---|
239 |
|
---|
240 | // _collectionoption_
|
---|
241 |
|
---|
242 | if (args["ccs"] == "1" && collectproto != NULL && (cinfo->ccsCols.size() > 1)) {
|
---|
243 | text_t collectionoption = "_textcollectionoption_";
|
---|
244 | text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
|
---|
245 | text_tarray::const_iterator col_end = cinfo->ccsCols.end();
|
---|
246 | int count = 0;
|
---|
247 | while (col_here != col_end) {
|
---|
248 | text_t colname;
|
---|
249 | if (*col_here == arg_c) {
|
---|
250 | colname = cinfo->collectionmeta["collectionname"];
|
---|
251 | } else {
|
---|
252 | ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
|
---|
253 | if (this_cinfo == NULL) {col_here ++; continue;}
|
---|
254 | colname = this_cinfo->collectionmeta["collectionname"];
|
---|
255 | }
|
---|
256 |
|
---|
257 | count ++;
|
---|
258 | collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
|
---|
259 | *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
|
---|
260 | colname + "<br>\n";
|
---|
261 | col_here ++;
|
---|
262 | }
|
---|
263 |
|
---|
264 | if (count > 1)
|
---|
265 | disp.setmacro ("collectionoption", "preferences", collectionoption);
|
---|
266 | }
|
---|
267 |
|
---|
268 | // _htmloptions_
|
---|
269 |
|
---|
270 | text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
|
---|
271 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
272 | disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
|
---|
273 |
|
---|
274 |
|
---|
275 | // _PreferenceDocsFromWeb_
|
---|
276 |
|
---|
277 | it = cinfo->format.find ("PreferenceDocsFromWeb");
|
---|
278 | if ((it == cinfo->format.end()) || ((*it).second == "true"))
|
---|
279 | disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
|
---|
280 | }
|
---|
281 |
|
---|
282 | // _languageoption_
|
---|
283 | // this is kind of a hack (another one!!). note that there're potential
|
---|
284 | // problems here as no checking is done anywhere to make sure language
|
---|
285 | // is set to a valid value. this does allow us to set which languages
|
---|
286 | // should go in the preference selection box (from collect.cfg) however
|
---|
287 | // and that's sufficient for current requirements
|
---|
288 |
|
---|
289 | // currently supported languages (_languageoption_ will default to all
|
---|
290 | // these languages unless PreferenceLanguages is set
|
---|
291 | text_tarray languages;
|
---|
292 | languages.push_back ("en");
|
---|
293 | languages.push_back ("fr");
|
---|
294 | languages.push_back ("de");
|
---|
295 | languages.push_back ("es");
|
---|
296 | languages.push_back ("mi");
|
---|
297 | languages.push_back ("zh");
|
---|
298 | languages.push_back ("ar");
|
---|
299 | text_tarray::const_iterator this_lang = languages.begin();
|
---|
300 | text_tarray::const_iterator end_lang = languages.end();
|
---|
301 |
|
---|
302 | text_t languageoption = "_textlanguage_\n<select name=\"l\" onChange=\"updatel();\">\n";
|
---|
303 | it = cinfo->format.find ("PreferenceLanguages");
|
---|
304 | if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
|
---|
305 | text_tset pref_langs;
|
---|
306 | splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
|
---|
307 | if (pref_langs.size() > 1) {
|
---|
308 | while (this_lang != end_lang) {
|
---|
309 | if (pref_langs.find(*this_lang) != pref_langs.end())
|
---|
310 | languageoption += "_" + *this_lang + "languageoption_\n";
|
---|
311 | this_lang ++;
|
---|
312 | }
|
---|
313 | languageoption += "</select>\n";
|
---|
314 | disp.setmacro ("languageoption", "preferences", languageoption);
|
---|
315 | }
|
---|
316 |
|
---|
317 | // _encodingoption_
|
---|
318 |
|
---|
319 | if (pref_langs.find("zh") == pref_langs.end())
|
---|
320 | disp.setmacro ("encodingoption", "preferences", "");
|
---|
321 |
|
---|
322 | } else {
|
---|
323 | while (this_lang != end_lang) {
|
---|
324 | languageoption += "_" + *this_lang + "languageoption_\n";
|
---|
325 | this_lang ++;
|
---|
326 | }
|
---|
327 | languageoption += "</select>\n";
|
---|
328 | disp.setmacro ("languageoption", "preferences", languageoption);
|
---|
329 | }
|
---|
330 |
|
---|
331 | } else if (arg_p == "about" || arg_p == "help") {
|
---|
332 | if (collectproto == NULL) return;
|
---|
333 |
|
---|
334 | // _textbrowseoptions_ and _numbrowseoptions_
|
---|
335 |
|
---|
336 | FilterResponse_t response;
|
---|
337 | text_tset metadata;
|
---|
338 | metadata.insert ("Title");
|
---|
339 | bool getParents = false;
|
---|
340 | get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
|
---|
341 |
|
---|
342 | disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
|
---|
343 |
|
---|
344 | ResultDocInfo_tarray::iterator here = response.docInfo.begin();
|
---|
345 | ResultDocInfo_tarray::iterator end = response.docInfo.end();
|
---|
346 |
|
---|
347 | // we're assuming that we've always got a search button
|
---|
348 | text_t shorttext = "<ul><li>_textSearchshort_\n";
|
---|
349 | text_t longtext = "_textSearchlong_";
|
---|
350 |
|
---|
351 | while (here != end) {
|
---|
352 | text_t title = (*here).metadata["Title"].values[0];
|
---|
353 |
|
---|
354 | text_t stext, ltext;
|
---|
355 | disp.expandstring ("help", "_text" + title + "short_", stext);
|
---|
356 | if (stext == ("_text" + title + "short_")) {
|
---|
357 | shorttext += "<li>_help:textdefaultshorttext_";
|
---|
358 | longtext += "_help:textdefaultlongtext_";
|
---|
359 | } else {
|
---|
360 | shorttext += "<li>" + stext;
|
---|
361 | longtext += "_help:text" + title + "long_";
|
---|
362 | }
|
---|
363 |
|
---|
364 | here ++;
|
---|
365 | }
|
---|
366 | shorttext += "</ul>\n";
|
---|
367 | if (response.docInfo.size() > 1) disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
|
---|
368 | else disp.setmacro ("textbrowseoptions", "help", longtext);
|
---|
369 |
|
---|
370 | if (arg_p == "help") {
|
---|
371 |
|
---|
372 | // _topicreadingdocs_ _textreadingdocs_ _texthelpreadingdocs_
|
---|
373 |
|
---|
374 | // if HTML collection there's no how to read document text
|
---|
375 | text_tmap::const_iterator it = cinfo->format.find ("HelpNoDocs");
|
---|
376 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
377 | disp.setmacro ("topicreadingdocs", "help", "");
|
---|
378 | disp.setmacro ("texthelpreadingdocs", "help", "");
|
---|
379 | }
|
---|
380 | it = cinfo->format.find ("HelpBibDocs");
|
---|
381 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
382 | disp.setmacro ("texthelpreadingdocs", "help", "_bibtexthelpreadingdocs_");
|
---|
383 | disp.setmacro ("textreadingdocs", "help", "_bibtextreadingdocs_");
|
---|
384 | }
|
---|
385 | it = cinfo->format.find ("HelpBookDocs");
|
---|
386 | if ((it != cinfo->format.end()) && ((*it).second == "true")) {
|
---|
387 | disp.setmacro ("texthelpreadingdocs", "help", "_booktexthelpreadingdocs_");
|
---|
388 | disp.setmacro ("textreadingdocs", "help", "_booktextreadingdocs_");
|
---|
389 | }
|
---|
390 |
|
---|
391 | }
|
---|
392 | if (arg_p == "about") {
|
---|
393 |
|
---|
394 | // _textsubcollections_
|
---|
395 | if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
|
---|
396 | text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
|
---|
397 | text_tarray::const_iterator here = cinfo->ccsCols.begin();
|
---|
398 | text_tarray::const_iterator end = cinfo->ccsCols.end();
|
---|
399 | bool first = true;
|
---|
400 | int count = 0;
|
---|
401 | while (here != end) {
|
---|
402 | if (*here == arg_c) {
|
---|
403 | if (!first) textsubcollections += "<br>";
|
---|
404 | textsubcollections += "\n" + cinfo->collectionmeta["collectionname"] + "\n";
|
---|
405 | } else {
|
---|
406 | ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
|
---|
407 | if (this_cinfo == NULL) {here ++; continue;}
|
---|
408 | if (!first) textsubcollections += "<br>";
|
---|
409 | textsubcollections += "\n" + this_cinfo->collectionmeta["collectionname"] + "\n";
|
---|
410 | }
|
---|
411 | count ++;
|
---|
412 | first = false;
|
---|
413 | here ++;
|
---|
414 | }
|
---|
415 | textsubcollections += "_textsubcols2_";
|
---|
416 | if (count > 1)
|
---|
417 | disp.setmacro ("textsubcollections", "about", textsubcollections);
|
---|
418 | }
|
---|
419 | }
|
---|
420 | }
|
---|
421 | }
|
---|
422 |
|
---|
423 | bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
|
---|
424 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
425 | outconvertclass &outconvert, ostream &textout,
|
---|
426 | ostream &/*logout*/) {
|
---|
427 |
|
---|
428 | text_t &arg_p = args["p"];
|
---|
429 |
|
---|
430 | textout << outconvert << disp << ("_" + arg_p + ":header_\n")
|
---|
431 | << ("_" + arg_p + ":content_\n")
|
---|
432 | << ("_" + arg_p + ":footer_\n");
|
---|
433 |
|
---|
434 | return true;
|
---|
435 | }
|
---|