source: trunk/gsdl/src/recpt/pageaction.cpp@ 866

Last change on this file since 866 was 866, checked in by sjboddie, 24 years ago

changes to set macros differently for preferences page depending
on type of collection - pageaction is getting kind of hacky - should
tidy it up some day

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.3 KB
Line 
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 * $Id: pageaction.cpp 866 2000-01-24 22:59:57Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.23 2000/01/24 22:59:57 sjboddie
31 changes to set macros differently for preferences page depending
32 on type of collection - pageaction is getting kind of hacky - should
33 tidy it up some day
34
35 Revision 1.22 1999/11/25 23:01:09 sjboddie
36 now need to be able to handle it if no collection is selected
37
38 Revision 1.21 1999/11/03 22:50:13 sjboddie
39 now defaults to home page
40
41 Revision 1.20 1999/11/01 21:58:02 sjboddie
42 changes to arguments of many functions, now pass list of protocols
43 instead of just that for this collection
44
45 Revision 1.19 1999/10/19 21:59:09 sjboddie
46 bug in generating "how to find information" text for about pages
47
48 Revision 1.18 1999/10/19 03:23:44 davidb
49 Collection building support through web pages
50 and internal and external link handling for collection documents
51
52 Revision 1.17 1999/10/14 23:04:44 sjboddie
53 some hacks to make nzdl home page look right
54
55 Revision 1.16 1999/10/10 08:14:09 sjboddie
56 - metadata now returns mp rather than array
57 - redesigned browsing support (although it's not finished so
58 won't currently work ;-)
59
60 Revision 1.15 1999/09/17 04:46:05 sjboddie
61 fixed a couple of problems with 'unknown' classifier
62
63 Revision 1.14 1999/09/07 23:08:09 rjmcnab
64 Removed some compiler warnings
65
66 Revision 1.13 1999/09/07 04:56:57 sjboddie
67 added GPL notice
68
69 Revision 1.12 1999/09/02 00:26:43 rjmcnab
70 made the p cgi argument always saved in the compressed arguments
71
72 Revision 1.11 1999/08/25 04:48:43 sjboddie
73 changes to the home and about pages
74
75 Revision 1.10 1999/08/11 23:29:43 sjboddie
76 added support for html classifier (i.e. the hp argument)
77
78 Revision 1.9 1999/08/03 03:29:47 sjboddie
79 added ability to set receptionist from collect.cfg
80
81 Revision 1.8 1999/07/30 02:24:44 sjboddie
82 added collectinfo argument to some functions
83
84 Revision 1.7 1999/06/24 05:12:24 sjboddie
85 lots of small changes
86
87 Revision 1.6 1999/06/10 00:39:16 sjboddie
88 navigation bar is no longer written out for every page (it should
89 be included in the _content_ macro of pages wanting to display it).
90
91 Revision 1.5 1999/06/08 04:29:35 sjboddie
92 added argsinfo to the call to check_cgiargs to make it easy to set
93 args to their default if they're found to be screwed up
94
95 Revision 1.4 1999/02/28 20:00:14 rjmcnab
96
97
98 Fixed a few things.
99
100 Revision 1.3 1999/02/25 21:58:58 rjmcnab
101
102 Merged sources.
103
104 Revision 1.2 1999/02/21 22:33:54 rjmcnab
105
106 Lots of stuff :-)
107
108 Revision 1.1 1999/02/12 02:40:17 sjboddie
109
110 Added page action
111
112 */
113
114#include "OIDtools.h"
115#include "pageaction.h"
116#include "receptionist.h"
117#include <time.h>
118
119pageaction::pageaction () {
120
121 recpt = NULL;
122
123 // this action uses cgi variables "a", "p", and "hp"
124 cgiarginfo arg_ainfo;
125 arg_ainfo.shortname = "a";
126 arg_ainfo.longname = "action";
127 arg_ainfo.multiplechar = true;
128 arg_ainfo.defaultstatus = cgiarginfo::weak;
129 arg_ainfo.argdefault = "p";
130 arg_ainfo.savedarginfo = cgiarginfo::must;
131 argsinfo.addarginfo (NULL, arg_ainfo);
132
133 arg_ainfo.shortname = "p";
134 arg_ainfo.longname = "page";
135 arg_ainfo.multiplechar = true;
136 arg_ainfo.defaultstatus = cgiarginfo::weak;
137 arg_ainfo.argdefault = "home";
138 arg_ainfo.savedarginfo = cgiarginfo::must;
139 argsinfo.addarginfo (NULL, arg_ainfo);
140
141 arg_ainfo.shortname = "hp";
142 arg_ainfo.longname = "html page";
143 arg_ainfo.multiplechar = true;
144 arg_ainfo.defaultstatus = cgiarginfo::weak;
145 arg_ainfo.argdefault = "";
146 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
147 argsinfo.addarginfo (NULL, arg_ainfo);
148}
149
150pageaction::~pageaction () {
151}
152
153bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
154 ostream &/*logout*/) {
155 // don't want to check anything yet.
156 return true;
157}
158
159void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
160 response_t &response,text_t &response_data,
161 ostream &/*logout*/) {
162 response = content;
163 response_data = "text/html";
164}
165
166void pageaction::set_homeextra_macro (displayclass &disp, recptprotolistclass *protos,
167 ostream &logout) {
168
169 text_t homeextra = "<center><table width=_pagewidth_><tr valign=top>\n";
170
171 recptprotolistclass::iterator rprotolist_here = protos->begin();
172 recptprotolistclass::iterator rprotolist_end = protos->end();
173 while (rprotolist_here != rprotolist_end) {
174 if ((*rprotolist_here).p != NULL) {
175
176 text_tarray collist;
177 comerror_t err;
178 (*rprotolist_here).p->get_collection_list (collist, err, logout);
179 if (err == noError) {
180 text_tarray::iterator collist_here = collist.begin();
181 text_tarray::iterator collist_end = collist.end();
182
183 int row1 = 7;
184 int row2 = 5;
185 int count = 1;
186 while (collist_here != collist_end) {
187
188 if (*collist_here == "niupepa")
189 homeextra += "<p><a href=\"_httpmusiclibrary_\">_iconmusiclibrary_</a>\n";
190
191 ColInfoResponse_t cinfo;
192 (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, logout);
193
194 if (err == noError) {
195 if (cinfo.isPublic && (cinfo.buildDate > 0)) {
196
197 FilterResponse_t response;
198 text_tset metadata;
199 metadata.insert ("collectionname");
200 metadata.insert ("iconcollection");
201 metadata.insert ("iconcollectionsmall");
202 text_t collectionname = *collist_here;
203 text_t alt = collectionname;
204 if (get_info ("collection", *collist_here, metadata, false,
205 (*rprotolist_here).p, response, logout)) {
206 if (!response.docInfo[0].metadata["collectionname"].values[0].empty())
207 alt = response.docInfo[0].metadata["collectionname"].values[0];
208
209 if (!response.docInfo[0].metadata["iconcollectionsmall"].values[0].empty())
210 collectionname = "<img width=150 border=1 src=\""
211 + response.docInfo[0].metadata["iconcollectionsmall"].values[0]
212 + "\" alt=\"" + alt + "\">";
213 else if (!response.docInfo[0].metadata["iconcollection"].values[0].empty())
214 collectionname = "<img width=150 border=1 src=\""
215 + response.docInfo[0].metadata["iconcollection"].values[0]
216 + "\" alt=\"" + alt + "\">";
217 else collectionname = alt;
218 }
219
220 if ((count == 1) || (count == (row1+1)) || (count == ((row1+row2)+1)))
221 homeextra += "<td align=center>";
222 else homeextra += "<p>";
223 text_t link = "<a href=\"_gwcgi_?a=p&p=about&c=" + *collist_here + "\">";
224 if (*collist_here == "chinese")
225 link = "<a href=\"_gwcgi_?a=p&p=about&l=zh&nw=u&c=" + *collist_here + "\">";
226 if (*collist_here == "arabic")
227 link = "<a href=\"_gwcgi_?a=p&p=about&w=a&c=" + *collist_here + "\">";
228
229 if (!cinfo.receptionist.empty())
230 link = "<a href=\"" + cinfo.receptionist + "\">";
231
232 homeextra += link + collectionname + "</a>\n";
233
234 if ((count == row1) || (count == (row1+row2)))
235 homeextra += "</td>";
236
237 count ++;
238 }
239 }
240
241 collist_here ++;
242 }
243 homeextra += "</tr></table></center>\n";
244 disp.setmacro ("homeextra", "home", homeextra);
245 }
246 }
247 rprotolist_here ++;
248 }
249}
250
251void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
252 recptprotolistclass *protos, ostream &logout) {
253
254 // define_internal_macros sets the following macros:
255
256 // _numdocs_ the number of documents in the collection
257
258 // _builddate_ the date last built
259
260
261 // if page is "home"
262 // _homeextra_ this is the list of available collections and collection info
263 // to be displayed on the home page
264
265
266 // if page is "preferences"
267 // _collectionoption_ collections to search/browse (if cross-collection-searching is on)
268
269 // _htmloptions_ set to _htmloptionson_ if DocumentUseHTML is set
270
271
272 // if page is "about"
273 // _textsubcollections_ the text on which subcollections make up the collection (if
274 // cross-collection searching is being used
275
276 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
277
278 // _numbrowseoptions_ the number of browsing options
279
280
281 // if page is "help"
282 // _textbrowseoptions_ the 'how to find information' text in the about and help pages
283
284 // _numbrowseoptions_ the number of browsing options
285
286
287 text_t &arg_p = args["p"];
288 text_t &arg_c = args["c"];
289 ColInfoResponse_t cinfo;
290 comerror_t err;
291
292 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
293 if (collectproto != NULL) {
294 collectproto->get_collectinfo (arg_c, cinfo, err, logout);
295
296 disp.setmacro ("numdocs", "Global", cinfo.numDocs);
297 unsigned long current_time = time(NULL);
298 unsigned long builddate = (current_time - cinfo.buildDate) / 86400;
299 disp.setmacro ("builddate", "Global", builddate);
300 }
301
302 if (arg_p == "home") set_homeextra_macro (disp, protos, logout);
303
304 else if (arg_p == "preferences") {
305
306 // _collectionoption_
307
308 if (args["ccs"] == "1" && collectproto != NULL && (cinfo.ccsCols.size() > 1)) {
309 text_t collectionoption = "_textcollectionoption_";
310 text_tarray::const_iterator col_here = cinfo.ccsCols.begin();
311 text_tarray::const_iterator col_end = cinfo.ccsCols.end();
312 while (col_here != col_end) {
313 text_t colname;
314 if (*col_here == arg_c) {
315 colname = cinfo.collectionmeta["collectionname"];
316 } else {
317 ColInfoResponse_t this_cinfo;
318 collectproto->get_collectinfo (*col_here, this_cinfo, err, logout);
319 colname = this_cinfo.collectionmeta["collectionname"];
320 }
321
322 collectionoption += "<input type=checkbox name=\"cc\" value=\"" +
323 *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
324 colname + "<br>\n";
325 col_here ++;
326 }
327
328 disp.setmacro ("collectionoption", "preferences", collectionoption);
329 }
330
331 // _htmloptions_
332
333 text_tmap::const_iterator it = cinfo.format.find ("DocumentUseHTML");
334 if ((it != cinfo.format.end()) && ((*it).second == "true"))
335 disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
336
337
338 } else if (arg_p == "about" || arg_p == "help") {
339 if (collectproto == NULL) return;
340
341 // _textbrowseoptions_ and _numbrowseoptions_
342
343 FilterResponse_t response;
344 text_tset metadata;
345 metadata.insert ("Title");
346 bool getParents = false;
347 get_children ("", args["c"], metadata, getParents, collectproto, response, logout);
348
349 disp.setmacro ("numbrowseoptions", "help", response.docInfo.size()+1);
350
351 ResultDocInfo_tarray::iterator here = response.docInfo.begin();
352 ResultDocInfo_tarray::iterator end = response.docInfo.end();
353
354 // we're assuming that we've always got a search button
355 text_t shorttext = "<ul><li>_textSearchshort_\n";
356 text_t longtext = "_textSearchlong_";
357
358 while (here != end) {
359 text_t title = (*here).metadata["Title"].values[0];
360
361 text_t stext, ltext;
362 disp.expandstring ("help", "_text" + title + "short_", stext);
363 if (stext == ("_text" + title + "short_")) {
364 shorttext += "<li>_help:textdefaultshorttext_";
365 longtext += "_help:textdefaultlongtext_";
366 } else {
367 shorttext += "<li>" + stext;
368 longtext += "_help:text" + title + "long_";
369 }
370
371 here ++;
372 }
373 shorttext += "</ul>\n";
374 disp.setmacro ("textbrowseoptions", "help", shorttext + longtext);
375
376 if (arg_p == "about") {
377
378 // _textsubcollections_
379 if (args["ccs"] == "1" && (cinfo.ccsCols.size() > 1)) {
380 text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo.ccsCols.size()) + ")";
381 text_tarray::const_iterator here = cinfo.ccsCols.begin();
382 text_tarray::const_iterator end = cinfo.ccsCols.end();
383 while (here != end) {
384 if (*here == arg_c) {
385 textsubcollections += "\n<br>" + cinfo.collectionmeta["collectionname"] + "\n";
386 } else {
387 ColInfoResponse_t this_cinfo;
388 collectproto->get_collectinfo (*here, this_cinfo, err, logout);
389 if (err == noError) {
390 textsubcollections += "\n<br>" + this_cinfo.collectionmeta["collectionname"] + "\n";
391 }
392 }
393 here ++;
394 }
395 textsubcollections += "_textsubcols2_";
396 disp.setmacro ("textsubcollections", "about", textsubcollections);
397 }
398 }
399 }
400}
401
402bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
403 browsermapclass * /*browsers*/, displayclass &disp,
404 outconvertclass &outconvert, ostream &textout,
405 ostream &/*logout*/) {
406
407 text_t &arg_p = args["p"];
408
409 textout << outconvert << disp << ("_" + arg_p + ":header_\n")
410 << ("_" + arg_p + ":content_\n")
411 << ("_" + arg_p + ":footer_\n");
412
413 return true;
414}
Note: See TracBrowser for help on using the repository browser.