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

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

now need to be able to handle it if no collection is selected

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