4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
28 my ($env,$searchstring,$type)=@_;
30 $searchstring=~ s/\'/\\\'/g;
31 my @data=split(' ',$searchstring);
33 my $query="Select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where (tagfield like \"$data[0]%\") order by tagfield";
34 my $sth=$dbh->prepare($query);
38 while (my $data=$sth->fetchrow_hashref){
45 return ($cnt,\@results);
49 my $searchfield=$input->param('searchfield');
50 my $pkfield="tagfield";
51 my $reqsel="select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where $pkfield='$searchfield'";
52 my $reqdel="delete from marc_tag_structure where $pkfield='$searchfield'";
53 my $offset=$input->param('offset');
54 my $script_name="/cgi-bin/koha/admin/marctagstructure.pl";
57 my $op = $input->param('op');
58 $searchfield=~ s/\,//g;
61 #start the page and read in includes
63 print startmenu('admin');
65 ################## ADD_FORM ##################################
66 # called by default. Used to create form to add or modify a record
67 if ($op eq 'add_form') {
68 #---- if primkey exists, it's a modify action, so read values to modify...
72 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where $pkfield='$searchfield'");
74 $data=$sth->fetchrow_hashref;
79 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80 function isNotNull(f,noalert) {
81 if (f.value.length ==0) {
86 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 var x=f.value.toUpperCase();
92 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
93 function isNum(v,maybenull) {
94 var n = new Number(v.value);
98 if (maybenull==0 && v.value=='') {
103 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105 var t = Date.parse(f.value);
110 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115 if (f.tagfield.value.length==0) {
116 _alertString += "- tagfield missing\\n";
118 if (f.repeatable.value!=0 && f.repeatable.value!=1) {
119 _alertString += "- repeatable must be 0 or 1\\n";
121 if (f.mandatory.value!=0 && f.mandatory.value!=1) {
122 _alertString += "- mandatory must be 0 or 1\\n";
124 if (_alertString.length==0) {
125 document.Aform.submit();
127 alertString2 = "Form not submitted because of the following problem(s)\\n";
128 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
129 alertString2 += _alertString;
137 print "<h1>Modify tag</h1>";
139 print "<h1>Add tag</h1>";
141 print "<form action='$script_name' name=Aform method=post>";
142 print "<input type=hidden name=op value='add_validate'>";
145 print "<tr><td>Tag</td><td><input type=hidden name=tagfield value='$searchfield'>$searchfield</td></tr>";
147 print "<tr><td>Tag</td><td><input type=text name=tagfield size=5 maxlength=3></td></tr>";
149 print "<tr><td>Value</td><td><input type=text name=liblibrarian size=80 maxlength=255 value='$data->{'liblibrarian'}'></td></tr>";
150 print "<tr><td>Value</td><td><input type=text name=libopac size=80 maxlength=255 value='$data->{'libopac'}'></td></tr>";
151 print "<tr><td>Value</td><td><input type=text name=repeatable value='$data->{'repeatable'}'></td></tr>";
152 print "<tr><td>Value</td><td><input type=text name=mandatory value='$data->{'mandatory'}'></td></tr>";
153 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
157 # END $OP eq ADD_FORM
158 ################## ADD_VALIDATE ##################################
159 # called by add_form, used to insert/modify data in DB
160 } elsif ($op eq 'add_validate') {
162 my $query = "replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory) values (";
163 $query.= $dbh->quote($input->param('tagfield')).",";
164 $query.= $dbh->quote($input->param('liblibrarian')).",";
165 $query.= $dbh->quote($input->param('libopac')).",";
166 $query.= $dbh->quote($input->param('repeatable')).",";
167 $query.= $dbh->quote($input->param('mandatory')).")";
168 my $sth=$dbh->prepare($query);
171 print "data recorded";
172 print "<form action='$script_name' method=post>";
173 print "<input type=submit value=OK>";
175 # END $OP eq ADD_VALIDATE
176 ################## DELETE_CONFIRM ##################################
177 # called by default form, used to confirm deletion of data in DB
178 } elsif ($op eq 'delete_confirm') {
179 my $dbh = &C4Connect;
180 my $sth=$dbh->prepare($reqsel);
182 my $data=$sth->fetchrow_hashref;
185 print mktablerow(2,'#99cc33',bold('Tag'),bold("$searchfield"),'/images/background-mem.gif');
186 print "<tr><td>liblibrarian</td><td>$data->{'liblibrarian'}</td></tr>";
187 print "<form action='$script_name' method=post><input type=hidden name=op value=delete_confirmed><input type=hidden name=searchfield value='$searchfield'>";
188 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
189 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>";
190 # END $OP eq DELETE_CONFIRM
191 ################## DELETE_CONFIRMED ##################################
192 # called by delete_confirm, used to effectively confirm deletion of data in DB
193 } elsif ($op eq 'delete_confirmed') {
195 # my $searchfield=$input->param('branchcode');
196 my $sth=$dbh->prepare($reqdel);
199 print "data deleted";
200 print "<form action='$script_name' method=post>";
201 print "<input type=submit value=OK>";
203 # END $OP eq DELETE_CONFIRMED
204 ################## DEFAULT ##################################
206 my @inputs=(["text","searchfield",$searchfield],
207 ["reset","reset","clr"]);
208 print mkheadr(2,'System preferences admin');
209 print mkformnotable("$script_name",@inputs);
213 if ($searchfield ne '') {
214 print "You Searched for <b>$searchfield<b><p>";
217 print mktablerow(5,'#99cc33',bold('Tag'),bold('Value'),
218 ' ',' ',' ','/images/background-mem.gif');
220 my ($count,$results)=StringSearch($env,$searchfield,'web');
222 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
223 if ($toggle eq 'white'){
228 print mktablerow(5,$toggle,$results->[$i]{'tagfield'},$results->[$i]{'liblibrarian'},mklink('','subfields_not_done'),
229 mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'},'Edit'),
230 mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'},'Delete'));
233 print "<form action='$script_name' method=post>";
234 print "<input type=hidden name=op value=add_form>";
236 my $prevpage = $offset-$pagesize;
237 print mklink("$script_name?offset=".$prevpage,'<< Prev');
239 print " ";
240 if ($offset+$pagesize<$count) {
241 my $nextpage =$offset+$pagesize;
242 print mklink("$script_name?offset=".$nextpage,'Next >>');
244 print "<br><input type=image src=\"/images/button-add-variable.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
246 } #---- END $OP eq DEFAULT
247 print endmenu('admin');