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