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