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

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

Removed CVS logging information from source files

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