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)=@_;
29 my $dbh = C4::Context->dbh;
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){
44 return ($cnt,\@results);
48 my $searchfield=$input->param('searchfield');
49 my $pkfield="tagfield";
50 my $reqsel="select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where $pkfield='$searchfield'";
51 my $reqdel="delete from marc_tag_structure where $pkfield='$searchfield'";
52 my $offset=$input->param('offset');
53 my $script_name="/cgi-bin/koha/admin/marctagstructure.pl";
56 my $op = $input->param('op');
57 $searchfield=~ s/\,//g;
60 #start the page and read in includes
62 print startmenu('admin');
64 ################## ADD_FORM ##################################
65 # called by default. Used to create form to add or modify a record
66 if ($op eq 'add_form') {
67 #---- if primkey exists, it's a modify action, so read values to modify...
70 my $dbh = C4::Context->dbh;
71 my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory from marc_tag_structure where $pkfield='$searchfield'");
73 $data=$sth->fetchrow_hashref;
78 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
79 function isNotNull(f,noalert) {
80 if (f.value.length ==0) {
85 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87 var x=f.value.toUpperCase();
91 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92 function isNum(v,maybenull) {
93 var n = new Number(v.value);
97 if (maybenull==0 && v.value=='') {
102 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
104 var t = Date.parse(f.value);
109 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
114 if (f.tagfield.value.length==0) {
115 _alertString += "- tagfield missing\\n";
117 if (f.repeatable.value!=0 && f.repeatable.value!=1) {
118 _alertString += "- repeatable must be 0 or 1\\n";
120 if (f.mandatory.value!=0 && f.mandatory.value!=1) {
121 _alertString += "- mandatory must be 0 or 1\\n";
123 if (_alertString.length==0) {
124 document.Aform.submit();
126 alertString2 = "Form not submitted because of the following problem(s)\\n";
127 alertString2 += "------------------------------------------------------------------------------------\\n\\n";
128 alertString2 += _alertString;
136 print "<h1>Modify tag</h1>";
138 print "<h1>Add tag</h1>";
140 print "<form action='$script_name' name=Aform method=post>";
141 print "<input type=hidden name=op value='add_validate'>";
144 print "<tr><td>Tag</td><td><input type=hidden name=tagfield value='$searchfield'>$searchfield</td></tr>";
146 print "<tr><td>Tag</td><td><input type=text name=tagfield size=5 maxlength=3></td></tr>";
148 print "<tr><td>Value</td><td><input type=text name=liblibrarian size=80 maxlength=255 value='$data->{'liblibrarian'}'></td></tr>";
149 print "<tr><td>Value</td><td><input type=text name=libopac size=80 maxlength=255 value='$data->{'libopac'}'></td></tr>";
150 print "<tr><td>Value</td><td><input type=text name=repeatable value='$data->{'repeatable'}'></td></tr>";
151 print "<tr><td>Value</td><td><input type=text name=mandatory value='$data->{'mandatory'}'></td></tr>";
152 print "<tr><td> </td><td><INPUT type=button value='OK' onClick='Check(this.form)'></td></tr>";
156 # END $OP eq ADD_FORM
157 ################## ADD_VALIDATE ##################################
158 # called by add_form, used to insert/modify data in DB
159 } elsif ($op eq 'add_validate') {
160 my $dbh = C4::Context->dbh;
161 my $query = "replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory) values (";
162 $query.= $dbh->quote($input->param('tagfield')).",";
163 $query.= $dbh->quote($input->param('liblibrarian')).",";
164 $query.= $dbh->quote($input->param('libopac')).",";
165 $query.= $dbh->quote($input->param('repeatable')).",";
166 $query.= $dbh->quote($input->param('mandatory')).")";
167 my $sth=$dbh->prepare($query);
170 print "data recorded";
171 print "<form action='$script_name' method=post>";
172 print "<input type=submit value=OK>";
174 # END $OP eq ADD_VALIDATE
175 ################## DELETE_CONFIRM ##################################
176 # called by default form, used to confirm deletion of data in DB
177 } elsif ($op eq 'delete_confirm') {
178 my $dbh = C4::Context->dbh;
179 my $sth=$dbh->prepare($reqsel);
181 my $data=$sth->fetchrow_hashref;
184 print mktablerow(2,'#99cc33',bold('Tag'),bold("$searchfield"),'/images/background-mem.gif');
185 print "<tr><td>liblibrarian</td><td>$data->{'liblibrarian'}</td></tr>";
186 print "<form action='$script_name' method=post><input type=hidden name=op value=delete_confirmed><input type=hidden name=searchfield value='$searchfield'>";
187 print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
188 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>";
189 # END $OP eq DELETE_CONFIRM
190 ################## DELETE_CONFIRMED ##################################
191 # called by delete_confirm, used to effectively confirm deletion of data in DB
192 } elsif ($op eq 'delete_confirmed') {
193 my $dbh = C4::Context->dbh;
194 # my $searchfield=$input->param('branchcode');
195 my $sth=$dbh->prepare($reqdel);
198 print "data deleted";
199 print "<form action='$script_name' method=post>";
200 print "<input type=submit value=OK>";
202 # END $OP eq DELETE_CONFIRMED
203 ################## DEFAULT ##################################
205 my @inputs=(["text","searchfield",$searchfield],
206 ["reset","reset","clr"]);
207 print mkheadr(2,'System preferences admin');
208 print mkformnotable("$script_name",@inputs);
212 if ($searchfield ne '') {
213 print "You Searched for <b>$searchfield<b><p>";
216 print mktablerow(5,'#99cc33',bold('Tag'),bold('Value'),
217 ' ',' ',' ','/images/background-mem.gif');
219 my ($count,$results)=StringSearch($env,$searchfield,'web');
221 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
222 if ($toggle eq 'white'){
227 print mktablerow(5,$toggle,$results->[$i]{'tagfield'},$results->[$i]{'liblibrarian'},mklink('','subfields_not_done'),
228 mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'},'Edit'),
229 mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'},'Delete'));
232 print "<form action='$script_name' method=post>";
233 print "<input type=hidden name=op value=add_form>";
235 my $prevpage = $offset-$pagesize;
236 print mklink("$script_name?offset=".$prevpage,'<< Prev');
238 print " ";
239 if ($offset+$pagesize<$count) {
240 my $nextpage =$offset+$pagesize;
241 print mklink("$script_name?offset=".$nextpage,'Next >>');
243 print "<br><input type=image src=\"/images/button-add-variable.gif\" WIDTH=188 HEIGHT=44 ALT=\"Add budget\" BORDER=0 ></a><br>";
245 } #---- END $OP eq DEFAULT
246 print endmenu('admin');