source: trunk/gsdl/src/recpt/delhistoryaction.cpp@ 940

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

tidied up a bit - replaced strings with macros etc.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/**********************************************************************
2 *
3 * delhistoryaction.cpp -- allows user to select history items to delete
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: delhistoryaction.cpp 940 2000-02-17 02:41:13Z sjboddie $
25 *
26 *********************************************************************/
27
28
29
30#include "delhistoryaction.h"
31//#include "querytools.h"
32//#include "formattools.h"
33#include "cgiutils.h"
34//#include "OIDtools.h"
35//#include "infodbclass.h"
36//#include "fileutil.h"
37#include "text_t.h"
38#include "historydb.h"
39
40
41delhistoryaction::delhistoryaction () {
42
43 // this action uses cgi variable "a"
44 cgiarginfo arg_ainfo;
45 arg_ainfo.shortname = "a";
46 arg_ainfo.longname = "action";
47 arg_ainfo.multiplechar = true;
48 arg_ainfo.defaultstatus = cgiarginfo::weak;
49 arg_ainfo.argdefault = "dh";
50 arg_ainfo.savedarginfo = cgiarginfo::must;
51 argsinfo.addarginfo (NULL, arg_ainfo);
52
53 // "hmode" -- indicate whether selected records are to be
54 // saved or deleted
55 arg_ainfo.shortname = "hmode";
56 arg_ainfo.longname = "history deletion mode";
57 arg_ainfo.multiplechar = true;
58 arg_ainfo.defaultstatus = cgiarginfo::weak;
59 arg_ainfo.argdefault = "delete";
60 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
61 argsinfo.addarginfo (NULL, arg_ainfo);
62
63 // "hsr" -- the selected records
64 arg_ainfo.shortname = "hsr";
65 arg_ainfo.longname = "history selected records";
66 arg_ainfo.multiplechar = true;
67 arg_ainfo.multiplevalue = true;
68 arg_ainfo.defaultstatus = cgiarginfo::weak;
69 arg_ainfo.argdefault = "";
70 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
71 argsinfo.addarginfo (NULL, arg_ainfo);
72
73 // "hdh" delete history for current user
74 // clear history = 0 = delete some, 1 = delete all
75 arg_ainfo.shortname = "hdh";
76 arg_ainfo.longname = "history delete history";
77 arg_ainfo.multiplechar = false;
78 arg_ainfo.multiplevalue = false;
79 arg_ainfo.defaultstatus = cgiarginfo::weak;
80 arg_ainfo.argdefault = "0";
81 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
82 argsinfo.addarginfo (NULL, arg_ainfo);
83
84}
85
86void delhistoryaction::configure (const text_t &key, const text_tarray &cfgline) {
87 action::configure (key, cfgline);
88}
89
90bool delhistoryaction::init (ostream &logout) {
91 return action::init (logout);
92}
93
94bool delhistoryaction::check_cgiargs (cgiargsinfoclass & /*argsinfo*/, cgiargsclass & /*args*/,
95 ostream &/*logout*/) {
96 //dont check anything yet
97 return true;
98}
99
100void delhistoryaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
101 response_t &response, text_t &response_data,
102 ostream &/*logout*/) {
103 response = content;
104 response_data = "text/html";
105}
106
107void delhistoryaction::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
108 recptprotolistclass */*protos*/,
109 ostream &/*logout*/) {
110
111 // define_internal_macros sets the following macros:
112 //_searchhistorylist_
113
114 // define_history_macros(disp, args, protos, logout);
115
116}
117
118
119void delhistoryaction::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
120 recptprotolistclass * /*protos*/, ostream &/*logout*/) {
121
122 // define_external_macros sets the following macros:
123
124 // can't do anything if collectproto is null (i.e. no collection was specified)
125 //recptproto *collectproto = protos->getrecptproto (args["c"], logout);
126 //if (collectproto == NULL) return;
127
128 // define_history_macros(disp, args, protos, logout);
129
130}
131
132
133void delhistoryaction::define_history_macros(displayclass &disp, cgiargsclass &args,
134 recptprotolistclass *protos, ostream &logout) {
135
136 // defines the following macros
137
138 // _searchhistorylist_
139
140 text_t historylist = "<!-- Search History List -->\n";
141
142 text_t userid = args["z"];
143 text_tarray entries;
144
145 historylist += "<table align=center width=500 border=1> \n <tr><th colspan=4 align=center>";
146 historylist += "_query:textsearchhistory_</th></tr>\n";
147 historylist += "<tr><th width=60>_textselect_</th><th width=40>#</th>\n<th width=340>_query:textquery_</th>\n";
148 historylist += "<th width=60>_query:textresults_</th></tr>\n";
149 if (get_history_info (userid, entries, logout)) {
150 int count = 1;
151 text_tarray::iterator here = entries.begin();
152 text_tarray::iterator end = entries.end();
153 // int size=(int)entries.size();
154 while (here !=end ) {
155 text_t c=count;
156 text_t querynum;
157 text_t query;
158 text_t numdocs;
159 text_t cgiargs;
160 text_t userinfo;
161 split_saved_query(*here, querynum, numdocs, cgiargs);
162 parse_saved_args(cgiargs, "q", query); // get query string out
163 decode_cgi_arg(query); // un cgisafe it
164
165 format_user_info(cgiargs, userinfo, protos, logout);
166
167 historylist += "<tr> <td width=60 align=center><input type=checkbox name=hsr value=\""+querynum+"\"></td>";
168 historylist += "<td width=40 align=center>"+querynum+"</td>\n";
169 historylist += "<td width=340 align=left>"+query+"</td><td width=60 align=center>"+numdocs+"</td>\n";
170 here++;
171 count++;
172 }
173
174
175 } // if
176 else { // have an empty row
177 historylist += "";
178 }
179 historylist+="</table>";
180 historylist += "<p><! ---- end of history list ----->\n";
181 disp.setmacro("searchhistorylist", "delhistory", historylist);
182
183} // define history macros
184
185
186bool delhistoryaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
187 browsermapclass * /*browsers*/, displayclass &disp,
188 outconvertclass &outconvert, ostream &textout,
189 ostream &logout) {
190
191 if (args["hdh"] !="") {
192 delete_search_history(args);
193 }
194 define_history_macros(disp, args, protos, logout);
195 textout << outconvert << disp << ("_delhistory:header_\n")
196 << ("_delhistory:content_\n")
197 << ("_delhistory:footer_\n");
198
199 return true;
200}
201
202
203bool delhistoryaction::delete_search_history (cgiargsclass &args) {
204
205 bool result;
206 text_t userid = args["z"];
207 text_t type = args["hdh"];
208 if (type == "1") {
209 result = delete_all_history_info (userid);
210 } else {
211 text_t records = args["hsr"];
212 text_t deletemode = args["hmode"];
213 result = delete_history_info (userid, deletemode, records);
214 }
215
216 return result;
217}
218
219
220
221
222
Note: See TracBrowser for help on using the repository browser.