3 #script to administer the stopwords table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
8 # this script use an $op to know what to do.
9 # if $op is empty or none of the above values,
10 # - the default screen is build (with all records, or filtered datas).
11 # - the user can clic on add, modify or delete record.
13 # - if primkey exists, this is a modification,so we read the $primkey record
14 # - builds the add/modify form
16 # - the user has just send datas, so we create/modify the record
18 # - we show the record having primkey=$primkey and ask for deletion validation form
19 # if $op=delete_confirm
20 # - we delete the record having primkey=$primkey
23 # Copyright 2000-2002 Katipo Communications
25 # This file is part of Koha.
27 # Koha is free software; you can redistribute it and/or modify it under the
28 # terms of the GNU General Public License as published by the Free Software
29 # Foundation; either version 2 of the License, or (at your option) any later
32 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
33 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
34 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License along with
37 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
38 # Suite 330, Boston, MA 02111-1307 USA
47 my ($env,$searchstring,$type)=@_;
48 my $dbh = C4::Context->dbh;
49 $searchstring=~ s/\'/\\\'/g;
50 my @data=split(' ',$searchstring);
52 my $query="Select word from stopwords where (word like \"$data[0]%\") order by word";
53 my $sth=$dbh->prepare($query);
57 while (my $data=$sth->fetchrow_hashref){
63 return ($cnt,\@results);
67 my $searchfield=$input->param('searchfield');
69 my $reqsel="select word from stopwords where $pkfield='$searchfield'";
70 my $reqdel="delete from stopwords where $pkfield='$searchfield'";
71 my $offset=$input->param('offset');
72 my $script_name="/cgi-bin/koha/admin/stopwords.pl";
75 my $op = $input->param('op');
76 $searchfield=~ s/\,//g;
79 #start the page and read in includes
81 print startmenu('admin');
83 ################## ADD_FORM ##################################
84 # called by default. Used to create form to add or modify a record
85 if ($op eq 'add_form') {
86 #---- if primkey exists, it's a modify action, so read values to modify...
89 my $dbh = C4::Context->dbh;
90 my $sth=$dbh->prepare("select word from stopwords where word='$searchfield'");
92 $data=$sth->fetchrow_hashref;
97 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98 function isNotNull(f,noalert) {
99 if (f.value.length ==0) {
104 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106 var x=f.value.toUpperCase();
110 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
111 function isNum(v,maybenull) {
112 var n = new Number(v.value);
116 if (maybenull==0 && v.value=='') {
121 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123 var t = Date.parse(f.value);
128 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133 if (f.word.value.length==0) {
134 _alertString += "- word missing\\n";
136 if (_alertString.length==0) {
137 document.Aform.submit();
139 alertString2 = "Form not submitted because of the following problem(s)\\n";
140 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
141 alertString2 += _alertString;
149 print "<h1>Modify word</h1>";
151 print "<h1>Add word</h1>";
153 print "<form action='$script_name' name=Aform method=post>";
154 print "<input type=hidden name=op value='add_validate'>";
157 print "<tr><td>Word</td><td><input type=hidden name=word value='$searchfield'>$searchfield</td></tr>";
159 print "<tr><td>Word</td><td><input type=text name=word size=255 maxlength=255></td></tr>";
161 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
165 # END $OP eq ADD_FORM
166 ################## ADD_VALIDATE ##################################
167 # called by add_form, used to insert/modify data in DB
168 } elsif ($op eq 'add_validate') {
169 my $dbh = C4::Context->dbh;
170 my $query = "replace stopwords (word) values (";
171 $query.= $dbh->quote($input->param('word')).")";
172 my $sth=$dbh->prepare($query);
175 print "data recorded";
176 print "<form action='$script_name' method=post>";
177 print "<input type=submit value=OK>";
179 # END $OP eq ADD_VALIDATE
180 ################## DELETE_CONFIRM ##################################
181 # called by default form, used to confirm deletion of data in DB
182 } elsif ($op eq 'delete_confirm') {
183 my $dbh = C4::Context->dbh;
184 my $sth=$dbh->prepare($reqsel);
186 my $data=$sth->fetchrow_hashref;
189 print mktablerow(2,'#99cc33',bold('Word'),bold("$searchfield"),'/images/background-mem.gif');
190 print "<form action='$script_name' method=post><input type=hidden name=op value=delete_confirmed><input type=hidden name=searchfield value='$searchfield'>";
191 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
192 print "<tr><td><INPUT type=submit value='YES'></form></td><td><form action='$script_name' method=post><input type=submit value=NO></form></td></tr>";
193 # END $OP eq DELETE_CONFIRM
194 ################## DELETE_CONFIRMED ##################################
195 # called by delete_confirm, used to effectively confirm deletion of data in DB
196 } elsif ($op eq 'delete_confirmed') {
197 my $dbh = C4::Context->dbh;
198 # my $searchfield=$input->param('branchcode');
199 my $sth=$dbh->prepare($reqdel);
202 print "data deleted";
203 print "<form action='$script_name' method=post>";
204 print "<input type=submit value=OK>";
206 # END $OP eq DELETE_CONFIRMED
207 ################## DEFAULT ##################################
209 my @inputs=(["text","searchfield",$searchfield],
210 ["reset","reset","clr"]);
211 print mkheadr(2,'Stopwords admin');
212 print mkformnotable("$script_name",@inputs);
217 if ($searchfield ne '') {
218 print "You Searched for <b>$searchfield<b><p>";
221 print mktablerow(2,'#99cc33',bold('Word'),
222 ' ',' ','/images/background-mem.gif');
224 my ($count,$results)=StringSearch($env,$searchfield,'web');
226 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
227 if ($toggle eq 'white'){
232 print mktablerow(2,$toggle,$results->[$i]{'word'},
233 mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'word'},'Delete'));
236 print "<form action='$script_name' method=post>";
237 print "<input type=hidden name=op value=add_form>";
239 my $prevpage = $offset-$pagesize;
240 print mklink("$script_name?offset=".$prevpage,'<< Prev');
242 print " ";
243 if ($offset+$pagesize<$count) {
244 my $nextpage =$offset+$pagesize;
245 print mklink("$script_name?offset=".$nextpage,'Next >>');
247 print "<br><input type=image src=\"/images/button-add-new.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
249 } #---- END $OP eq DEFAULT
250 print endmenu('admin');