1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * pageaction.cpp --
|
---|
4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * PUT COPYRIGHT NOTICE HERE
|
---|
7 | *
|
---|
8 | * $Id: pageaction.cpp 421 1999-07-30 02:24:45Z sjboddie $
|
---|
9 | *
|
---|
10 | *********************************************************************/
|
---|
11 |
|
---|
12 | /*
|
---|
13 | $Log$
|
---|
14 | Revision 1.8 1999/07/30 02:24:44 sjboddie
|
---|
15 | added collectinfo argument to some functions
|
---|
16 |
|
---|
17 | Revision 1.7 1999/06/24 05:12:24 sjboddie
|
---|
18 | lots of small changes
|
---|
19 |
|
---|
20 | Revision 1.6 1999/06/10 00:39:16 sjboddie
|
---|
21 | navigation bar is no longer written out for every page (it should
|
---|
22 | be included in the _content_ macro of pages wanting to display it).
|
---|
23 |
|
---|
24 | Revision 1.5 1999/06/08 04:29:35 sjboddie
|
---|
25 | added argsinfo to the call to check_cgiargs to make it easy to set
|
---|
26 | args to their default if they're found to be screwed up
|
---|
27 |
|
---|
28 | Revision 1.4 1999/02/28 20:00:14 rjmcnab
|
---|
29 |
|
---|
30 |
|
---|
31 | Fixed a few things.
|
---|
32 |
|
---|
33 | Revision 1.3 1999/02/25 21:58:58 rjmcnab
|
---|
34 |
|
---|
35 | Merged sources.
|
---|
36 |
|
---|
37 | Revision 1.2 1999/02/21 22:33:54 rjmcnab
|
---|
38 |
|
---|
39 | Lots of stuff :-)
|
---|
40 |
|
---|
41 | Revision 1.1 1999/02/12 02:40:17 sjboddie
|
---|
42 |
|
---|
43 | Added page action
|
---|
44 |
|
---|
45 | */
|
---|
46 |
|
---|
47 |
|
---|
48 | #include "pageaction.h"
|
---|
49 | #include "receptionist.h"
|
---|
50 | #include <time.h>
|
---|
51 |
|
---|
52 | pageaction::pageaction () {
|
---|
53 |
|
---|
54 | recpt = NULL;
|
---|
55 |
|
---|
56 | // this action uses cgi variables "a" and "p"
|
---|
57 | cgiarginfo arg_ainfo;
|
---|
58 | arg_ainfo.shortname = "a";
|
---|
59 | arg_ainfo.longname = "action";
|
---|
60 | arg_ainfo.multiplechar = true;
|
---|
61 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
62 | arg_ainfo.argdefault = "p";
|
---|
63 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
64 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
65 |
|
---|
66 | arg_ainfo.shortname = "p";
|
---|
67 | arg_ainfo.longname = "page";
|
---|
68 | arg_ainfo.multiplechar = true;
|
---|
69 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
70 | arg_ainfo.argdefault = "about";
|
---|
71 | arg_ainfo.savedarginfo = cgiarginfo::can;
|
---|
72 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
73 | }
|
---|
74 |
|
---|
75 | pageaction::~pageaction () {
|
---|
76 | }
|
---|
77 |
|
---|
78 | bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
|
---|
79 | ostream &/*logout*/) {
|
---|
80 | // don't want to check anything yet.
|
---|
81 | return true;
|
---|
82 | }
|
---|
83 |
|
---|
84 | void pageaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
|
---|
85 | text_t &response_data, ostream &/*logout*/) {
|
---|
86 | response = content;
|
---|
87 | response_data = "text/html";
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | // define all the macros which might be used by other actions
|
---|
92 | // to produce pages.
|
---|
93 | void pageaction::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
|
---|
94 | cgiargsclass &/*args*/, recptproto */*collectproto*/,
|
---|
95 | ostream &/*logout*/) {
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | void pageaction::define_internal_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &disp,
|
---|
100 | cgiargsclass &args, recptproto */*collectproto*/,
|
---|
101 | ostream &logout) {
|
---|
102 |
|
---|
103 | // define_internal_macros sets the following macros:
|
---|
104 |
|
---|
105 | // _homeextra_ this is the list of available collections and collection info
|
---|
106 | // to be displayed on the home page
|
---|
107 |
|
---|
108 | if (args["p"] == "home") {
|
---|
109 | // make sure we know about a receptionist
|
---|
110 | if (recpt == NULL) {
|
---|
111 | logout << "The page action does not contain information\n"
|
---|
112 | << "about any receptionists. The method set_receptionist\n"
|
---|
113 | << "was probably not called from the module which instantiated\n"
|
---|
114 | << "this page action.\n";
|
---|
115 | return;
|
---|
116 | }
|
---|
117 |
|
---|
118 | unsigned long current_time = time(NULL);
|
---|
119 | text_t homeextra;
|
---|
120 |
|
---|
121 | recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
|
---|
122 | if (rprotolist == NULL) return;
|
---|
123 |
|
---|
124 | recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
|
---|
125 | recptprotolistclass::iterator rprotolist_end = rprotolist->end();
|
---|
126 | while (rprotolist_here != rprotolist_end) {
|
---|
127 | if ((*rprotolist_here).p != NULL) {
|
---|
128 | text_tarray collist;
|
---|
129 | comerror_t err;
|
---|
130 | (*rprotolist_here).p->get_collection_list (collist, err, logout);
|
---|
131 | if (err == noError) {
|
---|
132 | text_tarray::iterator collist_here = collist.begin();
|
---|
133 | text_tarray::iterator collist_end = collist.end();
|
---|
134 |
|
---|
135 | homeextra += "<dl>\n";
|
---|
136 |
|
---|
137 | while (collist_here != collist_end) {
|
---|
138 | ColInfoResponse_t collectinfo;
|
---|
139 | (*rprotolist_here).p->get_collectinfo (*collist_here, collectinfo, err, logout);
|
---|
140 | if (err == noError) {
|
---|
141 |
|
---|
142 | homeextra += "<dt><a href=\"_httpquery_&c=" + *collist_here + "\">"
|
---|
143 | + *collist_here + "</a></dt>\n";
|
---|
144 | homeextra += "<dd>";
|
---|
145 | if (collectinfo.numDocs != 0) homeextra += text_t(collectinfo.numDocs) + "_documents_";
|
---|
146 | if (collectinfo.numWords != 0) homeextra += text_t(collectinfo.numWords) + "_words_";
|
---|
147 | unsigned long last_update = (current_time - collectinfo.buildDate) / 86400;
|
---|
148 | homeextra += "_lastupdate_ " + text_t(last_update) + " _ago_</dd>\n";
|
---|
149 | }
|
---|
150 | collist_here ++;
|
---|
151 | }
|
---|
152 | homeextra += "</dl>\n";
|
---|
153 | disp.setmacro ("homeextra", "home", homeextra);
|
---|
154 | }
|
---|
155 | }
|
---|
156 | rprotolist_here ++;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | bool pageaction::do_action (cgiargsclass &args, const ColInfoResponse_t &/*collectinfo*/,
|
---|
162 | recptproto */*collectproto*/, displayclass &disp,
|
---|
163 | outconvertclass &outconvert, ostream &textout,
|
---|
164 | ostream &/*logout*/) {
|
---|
165 |
|
---|
166 | text_t &arg_p = args["p"];
|
---|
167 |
|
---|
168 | textout << outconvert << disp << ("_" + arg_p + ":header_\n")
|
---|
169 | << ("_" + arg_p + ":content_\n")
|
---|
170 | << ("_" + arg_p + ":footer_\n");
|
---|
171 |
|
---|
172 | return true;
|
---|
173 | }
|
---|