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 "pageaction.h"
|
---|
27 | #include "receptionist.h"
|
---|
28 | #include "fileutil.h"
|
---|
29 |
|
---|
30 | pageaction::pageaction () {
|
---|
31 |
|
---|
32 | recpt = NULL;
|
---|
33 |
|
---|
34 | cgiarginfo arg_ainfo;
|
---|
35 | arg_ainfo.shortname = "a";
|
---|
36 | arg_ainfo.longname = "action";
|
---|
37 | arg_ainfo.multiplechar = true;
|
---|
38 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
39 | arg_ainfo.argdefault = "p";
|
---|
40 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
41 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
42 |
|
---|
43 | arg_ainfo.shortname = "p";
|
---|
44 | arg_ainfo.longname = "page";
|
---|
45 | arg_ainfo.multiplechar = true;
|
---|
46 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
47 | arg_ainfo.argdefault = "home";
|
---|
48 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
49 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
50 | }
|
---|
51 |
|
---|
52 | pageaction::~pageaction () {
|
---|
53 | }
|
---|
54 |
|
---|
55 | void pageaction::get_cgihead_info (cgiargsclass &args, response_t &response,
|
---|
56 | text_t &response_data, ostream &logout) {
|
---|
57 | response = content;
|
---|
58 | response_data = "text/html";
|
---|
59 | }
|
---|
60 |
|
---|
61 | bool pageaction::do_action (cgiargsclass &args, displayclass &disp,
|
---|
62 | outconvertclass &outconvert, ostream &textout,
|
---|
63 | ostream &logout) {
|
---|
64 |
|
---|
65 | text_t &arg_p = args["p"];
|
---|
66 |
|
---|
67 | textout << outconvert << disp << ("_" + arg_p + ":header_\n")
|
---|
68 | << ("_" + arg_p + ":content_\n")
|
---|
69 | << ("_" + arg_p + ":footer_\n");
|
---|
70 |
|
---|
71 | return true;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
75 | ostream &logout) {
|
---|
76 |
|
---|
77 | text_t &arg_p = args["p"];
|
---|
78 |
|
---|
79 | if (arg_p == "homepref") {
|
---|
80 | // set _languageoption_ and _encodingoption_
|
---|
81 | set_language_encoding_macros(disp, args, logout);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
|
---|
86 | ostream &logout) {
|
---|
87 | // _languageoption_
|
---|
88 | // Create the "interface language" selection box for the preferences pages.
|
---|
89 | text_t &arg_l = args["l"];
|
---|
90 | const recptconf &configinfo = recpt->get_configinfo();
|
---|
91 | // put languages in another map to sort them by longname
|
---|
92 | text_tmap languages;
|
---|
93 | languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
|
---|
94 | languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
|
---|
95 | while (thislang != endlang) {
|
---|
96 | languages[(*thislang).second.longname] = (*thislang).first;
|
---|
97 | thislang++;
|
---|
98 | }
|
---|
99 | text_tmap::iterator tlang = languages.begin();
|
---|
100 | text_tmap::iterator elang = languages.end();
|
---|
101 |
|
---|
102 | text_t languageoption;
|
---|
103 | bool collection_specific = false;
|
---|
104 |
|
---|
105 | if (!collection_specific) {
|
---|
106 | while (tlang != elang) {
|
---|
107 | languageoption += "<option value=\"" + (*tlang).second + "\"";
|
---|
108 | if ((*tlang).second == arg_l) languageoption += " selected";
|
---|
109 | languageoption += ">" + (*tlang).first + "\n";
|
---|
110 | tlang ++;
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | if (!languageoption.empty()) {
|
---|
115 | languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
|
---|
116 | languageoption += "</select>\n";
|
---|
117 | disp.setmacro ("languageoption", args["p"], languageoption);
|
---|
118 | }
|
---|
119 |
|
---|
120 | // _encodingoption_
|
---|
121 | // create the "encoding" selection box for the preferences page
|
---|
122 | // if (configinfo.encodings.size() > 1) {
|
---|
123 | text_t &arg_w = args["w"];
|
---|
124 | text_t encodingoption;
|
---|
125 | text_tmap::const_iterator thisenc = configinfo.encodings.begin();
|
---|
126 | text_tmap::const_iterator endenc = configinfo.encodings.end();
|
---|
127 | while (thisenc != endenc) {
|
---|
128 | encodingoption += "<option value=\"" + (*thisenc).second + "\"";
|
---|
129 | if ((*thisenc).second == arg_w) encodingoption += " selected";
|
---|
130 | encodingoption += ">" + (*thisenc).first + "\n";
|
---|
131 | thisenc ++;
|
---|
132 | }
|
---|
133 |
|
---|
134 | encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
|
---|
135 | encodingoption += "</select>\n";
|
---|
136 | disp.setmacro ("encodingoption", args["p"], encodingoption);
|
---|
137 | // }
|
---|
138 | }
|
---|