X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Fmarctagstructure.pl;h=fd8d7c251d0e5c040a324d2e5e7e0ef04e7d9c13;hb=e5a24bbbdd0d0e9ff09bfaadfe4c4bb37312e7ec;hp=5f25f808c8af22db7f1ab9d50e4643f6b59b70b4;hpb=34701939ab8e95e06946736f5f9359563348c57d;p=koha_fer
diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl
index 5f25f808c8..fd8d7c251d 100755
--- a/admin/marctagstructure.pl
+++ b/admin/marctagstructure.pl
@@ -14,80 +14,91 @@
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
+use warnings;
use CGI;
use C4::Auth;
+use C4::Koha;
use C4::Context;
use C4::Output;
-use C4::Interface::CGI::Output;
-use C4::Search;
use C4::Context;
-use HTML::Template;
-sub StringSearch {
- my ($env,$searchstring,$type)=@_;
- my $dbh = C4::Context->dbh;
- $searchstring=~ s/\'/\\\'/g;
- my @data=split(' ',$searchstring);
- my $count=@data;
- my $query="Select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where (tagfield >= $data[0]) order by tagfield";
- my $sth=$dbh->prepare($query);
- $sth->execute;
- my @results;
- my $cnt=0;
- while (my $data=$sth->fetchrow_hashref){
- push(@results,$data);
- $cnt ++;
- }
- # $sth->execute;
- $sth->finish;
- return ($cnt,\@results);
-}
+# retrieve parameters
my $input = new CGI;
-my $searchfield=$input->param('searchfield');
-$searchfield=0 unless $searchfield;
-my $pkfield="tagfield";
-my $reqsel="select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'";
-my $offset=$input->param('offset');
-my $script_name="/cgi-bin/koha/admin/marctagstructure.pl";
+my $frameworkcode = $input->param('frameworkcode') || ''; # set to select framework
+my $existingframeworkcode = $input->param('existingframeworkcode') || '';
+my $searchfield = $input->param('searchfield') || 0;
+# set when we have to create a new framework (in frameworkcode) by copying an old one (in existingframeworkcode)
+my $frameworkinfo = getframeworkinfo($frameworkcode);
+$searchfield=~ s/\,//g;
+
+my $offset = $input->param('offset') || 0;
+my $op = $input->param('op') || '';
+my $dspchoice = $input->param('select_display');
+my $pagesize = 20;
+
+my $script_name = "/cgi-bin/koha/admin/marctagstructure.pl";
my $dbh = C4::Context->dbh;
+# open template
my ($template, $loggedinuser, $cookie)
- = get_template_and_user({template_name => "parameters/marctagstructure.tmpl",
+ = get_template_and_user({template_name => "admin/marctagstructure.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
- flagsrequired => {parameters => 1},
+ flagsrequired => {parameters => 'parameters_remaining_permissions'},
debug => 1,
});
-my $pagesize=20;
-my $op = $input->param('op');
-$searchfield=~ s/\,//g;
-if ($op) {
-$template->param(script_name => $script_name,
- $op => 1); # we show only the TMPL_VAR names $op
-} else {
-$template->param(script_name => $script_name,
- else => 1); # we show only the TMPL_VAR names $op
+# get framework list
+my $frameworks = getframeworks();
+my @frameworkloop;
+foreach my $thisframeworkcode (keys %$frameworks) {
+ push @frameworkloop, {
+ value => $thisframeworkcode,
+ selected => ($thisframeworkcode eq $frameworkcode) ? 1 : 0,
+ frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
+ };
}
+# check that framework is defined in marc_tag_structure
+my $sth=$dbh->prepare("select count(*) from marc_tag_structure where frameworkcode=?");
+$sth->execute($frameworkcode);
+my ($frameworkexist) = $sth->fetchrow;
+unless ($frameworkexist) {
+ # if frameworkcode does not exists, then OP must be changed to "create framework" if we are not on the way to create it
+ # (op = itemtyp_create_confirm)
+ if ($op eq "framework_create_confirm") {
+ duplicate_framework($frameworkcode, $existingframeworkcode);
+ $op = ""; # unset $op to go back to framework list
+ } else {
+ $op = "framework_create";
+ }
+}
+$template->param(
+ frameworkloop => \@frameworkloop,
+ frameworkcode => $frameworkcode,
+ frameworktext => $frameworkinfo->{frameworktext},
+ script_name => $script_name,
+ ($op||'else') => 1,
+);
+
+
################## ADD_FORM ##################################
# called by default. Used to create form to add or modify a record
if ($op eq 'add_form') {
#---- if primkey exists, it's a modify action, so read values to modify...
my $data;
if ($searchfield) {
- my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where $pkfield='$searchfield'");
- $sth->execute;
+ $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=? and frameworkcode=?");
+ $sth->execute($searchfield,$frameworkcode);
$data=$sth->fetchrow_hashref;
- $sth->finish;
}
my $sth = $dbh->prepare("select distinct category from authorised_values");
$sth->execute;
@@ -99,113 +110,257 @@ if ($op eq 'add_form') {
my $authorised_value = CGI::scrolling_list(-name=>'authorised_value',
-values=> \@authorised_values,
-size=>1,
+ -id=>"authorised_value",
-multiple=>0,
-default => $data->{'authorised_value'},
);
if ($searchfield) {
- $template->param(action => "Modify tag",
- searchfield => "$searchfield");
+ $template->param(searchfield => $searchfield);
+ $template->param(action => "Modify tag");
+ $template->param('heading_modify_tag_p' => 1);
} else {
- $template->param(action => "Add tag",
- searchfield => "");
+ $template->param(action => "Add tag");
+ $template->param('heading_add_tag_p' => 1);
}
+ $template->param('use_heading_flags_p' => 1);
$template->param(liblibrarian => $data->{'liblibrarian'},
- libopac => $data->{'libopac'},
- repeatable => CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''),
- mandatory => CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''),
- authorised_value => $authorised_value,
- );
+ libopac => $data->{'libopac'},
+ repeatable => CGI::checkbox(-name=>'repeatable',
+ -checked=> $data->{'repeatable'}?'checked':'',
+ -value=> 1,
+ -label => '',
+ -id=> 'repeatable'),
+ mandatory => CGI::checkbox(-name => 'mandatory',
+ -checked => $data->{'mandatory'}?'checked':'',
+ -value => 1,
+ -label => '',
+ -id => 'mandatory'),
+ authorised_value => $authorised_value,
+ frameworkcode => $frameworkcode,
+ ); # FIXME: move checkboxes to presentation layer
# END $OP eq ADD_FORM
################## ADD_VALIDATE ##################################
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value) values (?,?,?,?,?,?)");
- my $tagfield =$input->param('tagfield');
- my $liblibrarian = $input->param('liblibrarian');
- my $libopac =$input->param('libopac');
- my $repeatable =$input->param('repeatable');
- my $mandatory =$input->param('mandatory');
- my $authorised_value =$input->param('authorised_value');
- unless (C4::Context->config('demo') eq 1) {
- $sth->execute($tagfield,
- $liblibrarian,
- $libopac,
- $repeatable?1:0,
- $mandatory?1:0,
- $authorised_value
- );
+ my $tagfield = $input->param('tagfield');
+ my $liblibrarian = $input->param('liblibrarian');
+ my $libopac = $input->param('libopac');
+ my $repeatable = $input->param('repeatable') ? 1 : 0;
+ my $mandatory = $input->param('mandatory') ? 1 : 0;
+ my $authorised_value = $input->param('authorised_value');
+ unless (C4::Context->config('demo') == 1) {
+ if ($input->param('modif')) {
+ $sth = $dbh->prepare(
+ "UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,authorised_value=? WHERE frameworkcode=? AND tagfield=?"
+ );
+ $sth->execute( $liblibrarian,
+ $libopac,
+ $repeatable,
+ $mandatory,
+ $authorised_value,
+ $frameworkcode,
+ $tagfield
+ );
+ } else {
+ $sth = $dbh->prepare(
+ "INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,frameworkcode) values (?,?,?,?,?,?,?)"
+ );
+ $sth->execute($tagfield,
+ $liblibrarian,
+ $libopac,
+ $repeatable,
+ $mandatory,
+ $authorised_value,
+ $frameworkcode
+ );
+ }
}
- $sth->finish;
- print "Content-Type: text/html\n\n