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
29 my ($env,$searchstring,$type)=@_;
31 $searchstring=~ s/\'/\\\'/g;
32 my @data=split(' ',$searchstring);
34 my $query="Select word from stopwords where (word like \"$data[0]%\") order by word";
35 my $sth=$dbh->prepare($query);
39 while (my $data=$sth->fetchrow_hashref){
46 return ($cnt,\@results);
50 my $searchfield=$input->param('searchfield');
52 my $reqsel="select word from stopwords where $pkfield='$searchfield'";
53 my $reqdel="delete from stopwords where $pkfield='$searchfield'";
54 my $offset=$input->param('offset');
55 my $script_name="/cgi-bin/koha/admin/stopwords.pl";
58 my $op = $input->param('op');
59 $searchfield=~ s/\,//g;
62 #start the page and read in includes
64 print startmenu('admin');
66 ################## ADD_FORM ##################################
67 # called by default. Used to create form to add or modify a record
68 if ($op eq 'add_form') {
69 #---- if primkey exists, it's a modify action, so read values to modify...
73 my $sth=$dbh->prepare("select word from stopwords where word='$searchfield'");
75 $data=$sth->fetchrow_hashref;
80 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 function isNotNull(f,noalert) {
82 if (f.value.length ==0) {
87 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89 var x=f.value.toUpperCase();
93 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 function isNum(v,maybenull) {
95 var n = new Number(v.value);
99 if (maybenull==0 && v.value=='') {
104 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106 var t = Date.parse(f.value);
111 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116 if (f.word.value.length==0) {
117 _alertString += "- word missing\\n";
119 if (_alertString.length==0) {
120 document.Aform.submit();
122 alertString2 = "Form not submitted because of the following problem(s)\\n";
123 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
124 alertString2 += _alertString;
132 print "<h1>Modify word</h1>";
134 print "<h1>Add word</h1>";
136 print "<form action='$script_name' name=Aform method=post>";
137 print "<input type=hidden name=op value='add_validate'>";
140 print "<tr><td>Word</td><td><input type=hidden name=word value='$searchfield'>$searchfield</td></tr>";
142 print "<tr><td>Word</td><td><input type=text name=word size=255 maxlength=255></td></tr>";
144 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
148 # END $OP eq ADD_FORM
149 ################## ADD_VALIDATE ##################################
150 # called by add_form, used to insert/modify data in DB
151 } elsif ($op eq 'add_validate') {
153 my $query = "replace stopwords (word) values (";
154 $query.= $dbh->quote($input->param('word')).")";
155 my $sth=$dbh->prepare($query);
158 print "data recorded";
159 print "<form action='$script_name' method=post>";
160 print "<input type=submit value=OK>";
162 # END $OP eq ADD_VALIDATE
163 ################## DELETE_CONFIRM ##################################
164 # called by default form, used to confirm deletion of data in DB
165 } elsif ($op eq 'delete_confirm') {
166 my $dbh = &C4Connect;
167 my $sth=$dbh->prepare($reqsel);
169 my $data=$sth->fetchrow_hashref;
172 print mktablerow(2,'#99cc33',bold('Word'),bold("$searchfield"),'/images/background-mem.gif');
173 print "<form action='$script_name' method=post><input type=hidden name=op value=delete_confirmed><input type=hidden name=searchfield value='$searchfield'>";
174 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
175 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>";
176 # END $OP eq DELETE_CONFIRM
177 ################## DELETE_CONFIRMED ##################################
178 # called by delete_confirm, used to effectively confirm deletion of data in DB
179 } elsif ($op eq 'delete_confirmed') {
181 # my $searchfield=$input->param('branchcode');
182 my $sth=$dbh->prepare($reqdel);
185 print "data deleted";
186 print "<form action='$script_name' method=post>";
187 print "<input type=submit value=OK>";
189 # END $OP eq DELETE_CONFIRMED
190 ################## DEFAULT ##################################
192 my @inputs=(["text","searchfield",$searchfield],
193 ["reset","reset","clr"]);
194 print mkheadr(2,'Currencies admin');
195 print mkformnotable("$script_name",@inputs);
200 if ($searchfield ne '') {
201 print "You Searched for <b>$searchfield<b><p>";
204 print mktablerow(2,'#99cc33',bold('Word'),
205 ' ',' ','/images/background-mem.gif');
207 my ($count,$results)=StringSearch($env,$searchfield,'web');
209 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
210 if ($toggle eq 'white'){
215 print mktablerow(2,$toggle,$results->[$i]{'word'},
216 mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'word'},'Delete',''));
219 print "<form action='$script_name' method=post>";
220 print "<input type=hidden name=op value=add_form>";
222 my $prevpage = $offset-$pagesize;
223 print mklink("$script_name?offset=".$prevpage,'<< Prev');
225 print " ";
226 if ($offset+$pagesize<$count) {
227 my $nextpage =$offset+$pagesize;
228 print mklink("$script_name?offset=".$nextpage,'Next >>');
230 print "<br><input type=image src=\"/images/button-add-new.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
232 } #---- END $OP eq DEFAULT
233 print endmenu('admin');