View | Details | Raw Unified | Return to bug 5725
Collapse All | Expand All

(-)a/C4/Biblio.pm (+101 lines)
Lines 128-133 BEGIN { Link Here
128
      &TransformHtmlToXml
128
      &TransformHtmlToXml
129
      &PrepareItemrecordDisplay
129
      &PrepareItemrecordDisplay
130
      &GetNoZebraIndexes
130
      &GetNoZebraIndexes
131
      &BatchModField
131
    );
132
    );
132
}
133
}
133
134
Lines 3681-3686 sub get_biblio_authorised_values { Link Here
3681
    return $authorised_values;
3682
    return $authorised_values;
3682
}
3683
}
3683
3684
3685
=head3 BatchModField
3686
3687
  Mod subfields in field record
3688
3689
  returns 1,$record if succeed
3690
  returns 0,$record if Action was not processed
3691
  returns -1 if no record
3692
  returns -2 if no action done on record
3693
3694
=cut
3695
3696
sub BatchModField {
3697
    my ( $record, $field, $subfield, $action, $condval, $nocond, $repval ) = @_;
3698
3699
    return -1 unless $record;
3700
    $condval=NormalizeString($condval);
3701
    my $condition=qr/$condval/;
3702
3703
    if($action eq "add"){
3704
        for my $rfield ($record->field($field)){
3705
            $rfield->add_subfields( $subfield => $repval );
3706
        }
3707
        return 1;
3708
    }elsif($action eq "addfield"){
3709
        my $new_field = MARC::Field->new($field,'','',
3710
                                         $subfield => $repval);
3711
        $record->insert_fields_ordered($new_field);
3712
        return 1;
3713
    } else {
3714
        my $done=0;
3715
        if ($field eq '000') {
3716
            my $value=$record->leader();
3717
            if ($value=~ s/$condition/$repval/){
3718
                $record->leader($repval);
3719
                $done=1;
3720
           }
3721
           if ( $nocond eq 'true'){
3722
            $record->leader($repval);
3723
            $done=1;
3724
           }
3725
        }
3726
        for my $rfield ($record->field($field)) {
3727
            if ($subfield && $subfield ne "@"){
3728
                my @subfields = $rfield->subfields();
3729
                my @subfields_to_add;
3730
                foreach my $subf (@subfields) {
3731
                    if ($subf->[0] eq $subfield){
3732
                        $subf->[1]=NormalizeString($subf->[1]);
3733
                        if ( $action eq "mod" ) {
3734
                            if ( $nocond ne "true" && $subf->[1] =~ s/$condition/$repval/) {
3735
                                $done=1;
3736
                            }
3737
                            if ($nocond eq "true"){
3738
                                $subf->[1] = $repval;
3739
                                $done=1;
3740
                            }
3741
                        } elsif ( $action eq "del" ) {
3742
                            if ( $subf->[1] =~ m/$condition/ || $nocond eq "true" ) {
3743
                                $done=1;
3744
                                next;
3745
                            }
3746
                        }
3747
                    }
3748
                    push @subfields_to_add,@$subf;
3749
                }
3750
                if ($done){
3751
                    if (@subfields_to_add){
3752
                        $rfield->replace_with(MARC::Field->new($rfield->tag,$rfield->indicator(1),$rfield->indicator(2),@subfields_to_add));
3753
                    }
3754
                    else {
3755
                        my $count= $record->delete_field($rfield);
3756
                    }
3757
                }
3758
            }
3759
            else {
3760
                if ($action eq "del"){
3761
                    my $count=$record->delete_field($rfield);
3762
                    $done=1;
3763
                }
3764
                else {
3765
                    if ($field < 10){
3766
                       my $value=$record->field($field)->data();
3767
                       if ($value=~ s/$condition/$repval/){
3768
                            $record->field($field)->update($value);
3769
                            $done=1;
3770
3771
                       }
3772
                       if ( $nocond eq 'true'){
3773
                        $record->field($field)->update($repval);
3774
                        $done=1;
3775
                       }
3776
                    }
3777
                }
3778
            }
3779
        }
3780
        return ($done,$record);
3781
    }
3782
    return -2;
3783
}
3784
3684
1;
3785
1;
3685
3786
3686
__END__
3787
__END__
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 4365-4371 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4365
4365
4366
$DBversion = "3.05.00.004";
4366
$DBversion = "3.05.00.004";
4367
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4367
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4368
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ShowReviewerPhoto',1,'If ON, photo of reviewer will be shown beside comments in OPAC',NULL,'YesNo');");
4368
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ShowReviewerPhoto',1,'If ON, photo of reviewer will be shown beside comments in OPAC',NULL,'YesNo')");
4369
    print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n";
4369
    print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n";
4370
    SetVersion($DBversion);    
4370
    SetVersion($DBversion);    
4371
}
4371
}
Lines 4436-4441 $DBversion = "3.05.00.010"; Link Here
4436
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4436
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4437
    $dbh->do("CREATE INDEX priorityfoundidx ON reserves (priority,found)");
4437
    $dbh->do("CREATE INDEX priorityfoundidx ON reserves (priority,found)");
4438
    print "Create an index on reserves to speed up holds awaiting pickup report bug 5866\n";
4438
    print "Create an index on reserves to speed up holds awaiting pickup report bug 5866\n";
4439
}
4440
4441
$DBversion = "3.05.00.XXX";
4442
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4443
    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchedit', 'Batch editing biblios')");
4444
    print "Upgrade to $DBversion done (batch edit permission)\n";
4439
    SetVersion($DBversion);
4445
    SetVersion($DBversion);
4440
}
4446
}
4441
4447
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/basket.js (+6 lines)
Lines 433-436 $(document).ready(function(){ Link Here
433
	if(basketcount){ updateBasket(basketcount); }
433
	if(basketcount){ updateBasket(basketcount); }
434
});
434
});
435
435
436
function batchEdit(){
437
    var valCookie = readCookie(nameCookie);
438
    var strCookie = nameParam + "=" + valCookie;
436
439
440
    var loc = CGIBIN + "tools/batchedit.pl?" + strCookie;
441
    window.opener.location = loc;
442
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt (+7 lines)
Lines 86-91 function placeHold () { Link Here
86
		[% IF ( verbose ) %]<a href="basket.pl" class="brief" onclick="showLess(); return false;">Brief Display</a>[% ELSE %]<a href="basket.pl" class="detail" onclick="showMore(); return false;">More Details</a>[% END %]
86
		[% IF ( verbose ) %]<a href="basket.pl" class="brief" onclick="showLess(); return false;">Brief Display</a>[% ELSE %]<a href="basket.pl" class="detail" onclick="showMore(); return false;">More Details</a>[% END %]
87
	    </span></span>
87
	    </span></span>
88
	</li>
88
	</li>
89
    [% IF ( CAN_user_tools_batchedit ) %]
90
    <li>
91
        <span id="batchedit" class="yui-button yui-link-button"><span class="first-child">
92
        <a class="batchedit" href="basket.pl" onclick="batchEdit(); return false;">Batch Edit</a>
93
        </span></span>
94
    </li>
95
    [% END %]
89
	<li>
96
	<li>
90
	    <span id="receive" class="yui-button yui-link-button"><span class="first-child">
97
	    <span id="receive" class="yui-button yui-link-button"><span class="first-child">
91
		<a class="send" href="basket.pl" onclick="sendBasket(); return false;">Send</a>
98
		<a class="send" href="basket.pl" onclick="sendBasket(); return false;">Send</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchedit.tt (+257 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Batch record of modification</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
5
[% UNLESS ( modsuccess ) %]
6
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
7
<script type="text/JavaScript" language="JavaScript">
8
//<![CDATA[
9
     var CGIBIN = "/cgi-bin/koha/";
10
11
     function fieldChanged(){
12
        var field = $('#fieldchoice').val();
13
        $("#loading").html(" <img src=\"/intranet-tmpl/prog/img/loading-small.gif\" alt=\"\" />");
14
        $.ajax({
15
		url: CGIBIN + 'tools/batchedit.pl?field=' + field,
16
		dataType: 'json',
17
            success: function(data){
18
            $("#loading").html("");
19
		$("#subfieldchoice option").remove();
20
21
		    var subfield = $('#subfieldchoice');
22
			$("<option>").attr("value", "@")
23
                                 .text( _('Whole field'))
24
                                 .appendTo('#subfieldchoice');
25
                for( var i=0; i < data.length ; i++){
26
			$("<option>").attr("value", data[i].subfield)
27
                                 .text(data[i].subfield)
28
                                 .appendTo('#subfieldchoice');
29
                }
30
                subfieldChanged();
31
            }
32
        });
33
     }
34
35
     function subfieldChanged(){
36
        var field    = $('#fieldchoice').val();
37
        var subfield = $('#subfieldchoice').val();
38
        $.ajax({
39
		url: CGIBIN + 'tools/batchedit.pl?field=' + field + '&subfield=' + subfield,
40
		dataType: 'json',
41
            success: function(data){
42
43
		    if( data.length > 0) {
44
			$("#condvaltd").html('<select name="condvalchoice" id="condvalchoice" />');
45
			$("<option>").attr("value", "")
46
                        .text("")
47
                        .appendTo('#condvalchoice');
48
			$("#repvaltd" ).html('<select name="repvalchoice" id="repvalchoice" />'  );
49
                    $("<option>").attr("value", "")
50
                        .text("")
51
                        .appendTo('#repvalchoice');
52
53
                    for( var i=0; i < data.length ; i++){
54
			$("<option>").attr("value", data[i].code)
55
                            .text(data[i].value)
56
                            .appendTo('#repvalchoice');
57
			$("<option>").attr("value", data[i].code)
58
                            .text(data[i].value)
59
                            .appendTo('#condvalchoice');
60
                    }
61
		    }else{
62
                    $("#condvaltd").html('<input type="text" name="condvalchoice" id="condvalchoice" />');
63
                    $("#repvaltd").html('<input type="text" name="repvalchoice"  id="repvalchoice" />');
64
		    }
65
                $('<label> <input type="checkbox" id="nocond" name="nocond" value="nocond" onClick="$(\'#condvalchoice\').attr(\'disabled\', ! $(\'#condvalchoice\').attr(\'disabled\') ) " />  All</label>').appendTo("#condvaltd");
66
            }
67
        });
68
69
     }
70
71
     function addRule(){
72
        var actionlabel = {
73
                mod: _('Modify'),
74
                del: _('Delete'),
75
                add: _('Create')
76
                };
77
        var repvallabel  = $('#repvalchoice :selected').text()  || $("#repvalchoice").val();
78
79
        var field    = $('#fieldchoice').val();
80
        var subfield = $('#subfieldchoice').val();
81
        var action   = $('#actionchoice').val();
82
        var nocond   = $('#nocond').attr('checked')||(! $('#condvalchoice').val().length);
83
84
        if( ! nocond ) {
85
            var condval  = $('#condvalchoice').val();
86
            var condvallabel = $('#condvalchoice :selected').text() || $("#condvalchoice").val();
87
        }else{
88
            var condvallabel = _("No condition");
89
        }
90
        var repval   = $('#repvalchoice').val();
91
92
        var tmpl = "<tr>"
93
                + '<td><input type="hidden" name="field" value="'    + field + '" />'    + field               + '</td>'
94
                + '<td><input type="hidden" name="subfield" value="' + subfield + '" />' + subfield            + '</td>'
95
                + '<td><input type="hidden" name="action" value="'   + action + '" />'   + actionlabel[action] + '</td>'
96
                + '<td><input type="hidden" name="condval" value="'  + condval + '" />'
97
                    + condvallabel
98
                    + '<input type="hidden" name="nocondval" value="' + nocond + '" />'
99
                + '</td>'
100
101
                + '<td><input type="hidden" name="repval" value="'   + repval + '" />'   + repvallabel         + '</td>'
102
                + '<td><input type="button" value="Delete" onclick="deleteRule(this)" /></td>'
103
            + '</tr>';
104
        $('#rulestable').append(tmpl);
105
106
     }
107
108
     function deleteRule(button){
109
        $(button).parent().parent().remove();
110
        return false;
111
     }
112
113
114
//]]>
115
</script>
116
[% END %]
117
</head>
118
<body>
119
[% INCLUDE 'header.inc' %]
120
[% INCLUDE 'cat-search.inc' %]
121
122
<div id="breadcrumbs">
123
  <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
124
  <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
125
  <a href="/cgi-bin/koha/tools/batchedit.pl">Batch record modification</a>
126
</div>
127
128
<div id="doc3" class="yui-t2">
129
    <div id="bd">
130
        <div id="yui-main">
131
            <div class="yui-b">
132
133
<form method="post" action="/cgi-bin/koha/tools/batchedit.pl" enctype="multipart/form-data">
134
[% IF ( moddone ) %]
135
    <div class="dialog message">All operations processed</div>
136
[% END %]
137
138
[% UNLESS ( bib_list ) %]
139
    <h2>Batch record modification</h2>
140
    <div class="yui-g">
141
    <div class="yui-u first">
142
    <fieldset class="rows">
143
	<legend>Use a file of biblionumbers</legend>
144
	<ol>
145
	    <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
146
	</ol>
147
    </fieldset>
148
    </div>
149
    <div class="yui-u">
150
    <div class="container">
151
    <p><b>Reminder</b>: You can also add records to your cart and reach this page from the cart.</p>
152
    </div>
153
    </div>
154
    </div>
155
    <fieldset class="rows">
156
	<legend>Or enter records one by one</legend>
157
	<ol>
158
	    <li>
159
		<label for="recordslist">One biblionumber per line: </label>
160
		<textarea rows="10" cols="30" id="recordslist" name="recordslist"></textarea>
161
	    </li>
162
	</ol>
163
    
164
    </fieldset>
165
[% ELSE %]
166
    <h2>List of records:</h2>
167
    <table id="bibliolist">
168
        <thead>
169
            <tr>
170
                <th>Biblionumber</th><th>Title</th><th>Author</th>[% IF ( moddone ) %] <th>Status</th>[% END %]
171
            </tr>
172
        </thead>
173
        [% FOREACH biblioinfo IN biblioinfos %]
174
            <tr>
175
                <td>[% biblioinfo.biblionumber %]</td>
176
                <td>[% biblionumber = biblioinfo.biblionumber %] [% INCLUDE 'biblio-default-view.inc' %][% IF ( biblioinfo.title ) %][% biblioinfo.title |html %][% ELSE %]No title[% END %]</a></td>
177
                <td>[% biblioinfo.author %]</td>
178
                [% IF ( moddone ) %]
179
                    [% IF ( biblioinfo.OK ) %]
180
                        <td>
181
                    [% ELSE %]
182
                        <td class="problem">
183
                    [% END %]
184
                    [% IF ( biblioinfo.OK ) %]OK[% END %]
185
                    [% IF ( biblioinfo.No_Actions ) %]Nothing done[% END %]
186
                    [% IF ( biblioinfo.Actions_Failed ) %]
187
                        Some actions failed. List follow : <ul>[% FOREACH failed_action IN biblioinfo.failed_actions %]<li>[% failed_action.action %]</li>[% END %]</ul>
188
                    [% END %]
189
                    </td>
190
                [% END %]
191
            </tr>
192
        [% END %]
193
    </table>
194
[% END %]
195
196
[% UNLESS ( moddone ) %]
197
198
    [% IF ( bib_list ) %]
199
        <fieldset class="rows">
200
        <h2>Modification rules:</h2>
201
        <input type="hidden" name="op" value="do" />
202
        <input type="hidden" name="bib_list" value="[% bib_list %]" />
203
        <table id="rulestable">
204
            <thead>
205
                <tr>
206
                    <th>Field</th><th>Subfield</th><th>Action</th><th>Condition Value</th><th>Value</th><th>&nbsp;</th>
207
                </tr>
208
            </thead>
209
                <tr>
210
                    <td>
211
                        <select name="fieldchoice" id="fieldchoice" onchange="fieldChanged();">
212
                        <option value=""></option>
213
                        [% FOREACH marcfield IN marcfields %]
214
                            <option value="[% marcfield.tag %]">[% marcfield.tag %]</option>
215
                        [% END %]
216
                        </select>
217
                    </td>
218
                    <td>
219
                        <select name="subfieldchoice" id="subfieldchoice" onchange="subfieldChanged();">
220
                        </select><span id="loading"></span>
221
                    </td>
222
                    <td>
223
                        <select name="actionchoice" id="actionchoice">
224
                            <option value="mod">Modify subfield</option>
225
                            <option value="add">Create subfield</option>
226
                            <option value="addfield">Create field and subfield</option>
227
                            <option value="del">Delete subfield</option>
228
                        </select>
229
                    </td>
230
                    <td id="condvaltd">
231
                        <input type="text" name="condvalchoice" id="condvalchoice" />
232
                        <label> <input type="checkbox" id="nocond" name="nocond" value="nocond" onclick="$('#condvalchoice').attr('disabled', ! $('#condvalchoice').attr('disabled') ) " />  All </label>
233
                    </td>
234
                    <td id="repvaltd">
235
                        <input type="text" name="repvalchoice" id="repvalchoice" />
236
                    </td>
237
                    <td><input type="button" value="Add" onclick="addRule();" /></td>
238
                </tr>
239
            </thead>
240
241
        </table>
242
        <input type="hidden" name="bib_list" value="[% bib_list %]" />
243
        <fieldset class="action"><input type="submit" value="Submit" /> (don't forget to click "Add" button on the right of the previous form before submitting)</fieldset>
244
        </fieldset>
245
        </form>
246
    [% ELSE %]
247
        <fieldset class="action"><input type="submit" value="Submit" /></fieldset>
248
        </form>
249
    [% END %]
250
[% END %]
251
            </div>
252
        </div>
253
       <div class="yui-b">
254
            [% INCLUDE 'tools-menu.inc' %]
255
        </div>
256
    </div>
257
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (+5 lines)
Lines 103-108 Link Here
103
    <dd>Modify items in a batch</dd>
103
    <dd>Modify items in a batch</dd>
104
    [% END %]
104
    [% END %]
105
    
105
    
106
    [% IF ( CAN_user_tools_batchedit ) %]
107
    <dt><a href="/cgi-bin/koha/tools/batchedit.pl">Batch biblio modification</a></dt>
108
    <dd>Modify biblios in a batch</dd>
109
    [% END %]
110
    
106
    [% IF ( CAN_user_tools_export_catalog ) %]
111
    [% IF ( CAN_user_tools_export_catalog ) %]
107
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export bibliographic and holdings</a></dt>
112
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export bibliographic and holdings</a></dt>
108
    <dd>Export bibliographic and holdings data</dd>
113
    <dd>Export bibliographic and holdings data</dd>
(-)a/tools/batchedit.pl (-1 / +221 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
4
# Copyright 2010 SARL BibLibre
5
#
6
# This file is part of Koha.
7
#
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
11
# version.
12
#
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.
16
#
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
20
21
use CGI;
22
use strict;
23
use C4::Output;
24
use C4::Auth;
25
use C4::Branch;
26
use C4::Koha;
27
use C4::Biblio;
28
use C4::Context;
29
use C4::Debug;
30
use JSON;
31
32
my $input = new CGI;
33
my $dbh = C4::Context->dbh;
34
35
my $filefh = $input->param('uploadfile');
36
my $recordslist = $input->param('recordslist');
37
my $bib_list = $input->param('bib_list');
38
my @biblionumbers;
39
40
#retrieve the list of biblionumber, from a file, a list entered manually or the basket
41
if ($filefh) {
42
    while ( my $biblionumber = <$filefh> ) {
43
        $biblionumber =~ s/[\r\n]*$//g;
44
        push @biblionumbers, $biblionumber if $biblionumber;
45
    }
46
} elsif ($recordslist) {
47
    push @biblionumbers, split( /\s\n/, $recordslist );
48
} elsif ($bib_list) {
49
    push @biblionumbers, split('/', $bib_list);
50
}
51
52
my $op            = $input->param('op');
53
my ($template, $loggedinuser, $cookie);
54
55
my $frameworkcode="";
56
my $tagslib = &GetMarcStructure(1,$frameworkcode);
57
my %report_actions;
58
59
# if this script is called by ajax, buid an ajax/xml answer
60
if($input->param('field') and not defined $op){
61
    ($template, $loggedinuser, $cookie)
62
        = get_template_and_user({template_name => "acqui/ajax.tmpl",
63
                 query => $input,
64
                 type => "intranet",
65
                 authnotrequired => 0,
66
                 flagsrequired => { tools => "batchedit" },
67
        });
68
69
70
    my $tag      = $input->param('field');
71
    my $subfield = $input->param('subfield');
72
73
    if($input->param('subfield')){
74
        my $branches = GetBranchesLoop();
75
76
        my @authorised_values;
77
        if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
78
             if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
79
                foreach my $thisbranch (@$branches) {
80
                    push @authorised_values, {
81
                            code => $thisbranch->{value},
82
                            value => $thisbranch->{branchname},
83
                        };
84
                    # $value = $thisbranch->{value} if $thisbranch->{selected};
85
                }
86
             }elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
87
                 my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
88
                 $sth->execute();
89
                 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
90
                    push @authorised_values, {
91
                        code => $itemtype,
92
                        value => $description,
93
                    };
94
                 }
95
96
            }else {
97
                  # Getting the fields where the item location is
98
                  my ($location_field, $location_subfield) = GetMarcFromKohaField('items.location', $frameworkcode);
99
100
                  # Getting the name of the authorised values' category for item location
101
                  my $item_location_category = $tagslib->{$location_field}->{$location_subfield}->{'authorised_value'};
102
		      # Are we dealing with item location ?
103
                  my $item_location = ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) ? 1 : 0;
104
105
                  # If so, we sort by authorised_value, else by libelle
106
                  my $orderby = $item_location ? 'authorised_value' : 'lib';
107
108
                  my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY $orderby");
109
110
                  $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value});
111
112
113
                  while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
114
                    push @authorised_values, {
115
                        code => $value,
116
                        value => ($item_location) ? $value . " - " . $lib : $lib,
117
                    };
118
119
                  }
120
            }
121
        }
122
      $template->param('return' => to_json(\@authorised_values));
123
    }else{
124
        my @modifiablesubf;
125
126
        foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
127
            next if subfield_is_koha_internal_p($subfield);
128
            next if $subfield eq "@";
129
            next if ($tagslib->{$tag}->{$subfield}->{'tab'} eq "10");
130
            my %subfield_data;
131
            $subfield_data{subfield} = $subfield;
132
            push @modifiablesubf, \%subfield_data;
133
        }
134
        $template->param('return' => to_json(\@modifiablesubf));
135
    }
136
137
138
    output_html_with_http_headers $input, $cookie, $template->output;
139
    exit;
140
}else{
141
# standard call (via web browser)
142
    ($template, $loggedinuser, $cookie)
143
            = get_template_and_user({template_name => "tools/batchedit.tmpl",
144
                     query => $input,
145
                     type => "intranet",
146
                     authnotrequired => 0,
147
                     flagsrequired => { tools => "batchedit" },
148
                     });
149
150
    $template->param( bib_list => join('/', @biblionumbers));
151
    # if no $op, just display the form
152
    if(!defined $op) {
153
        my @modifiablefields;
154
155
        foreach my $tag (sort keys %{$tagslib}) {
156
            my %subfield_data;
157
            foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
158
                next if $subfield_data{tag};
159
                next if subfield_is_koha_internal_p($subfield);
160
                next if ($tagslib->{$tag}->{$subfield}->{'tab'} eq "10");
161
162
                $subfield_data{tag}      = $tag;
163
164
                push @modifiablefields, \%subfield_data;
165
            }
166
        }
167
        $template->param(marcfields  => \@modifiablefields,
168
                         );
169
170
    }else{
171
        my @fields     = $input->param('field');
172
        my @subfields  = $input->param('subfield');
173
        my @actions    = $input->param('action');
174
        my @condvals   = $input->param('condval');
175
        my @nocondvals = $input->param('nocondval');
176
        my @repvals    = $input->param('repval');
177
        foreach my $biblionumber ( @biblionumbers ){
178
            my $record = GetMarcBiblio($biblionumber);
179
            my ($count, $biblio) = GetBiblio($biblionumber);
180
            my @failed_actions;
181
            for(my $i = 0 ; $i < scalar(@fields) ; $i++ ){
182
                my $field    = $fields[$i];
183
                my $subfield = $subfields[$i];
184
                my $action   = $actions[$i];
185
                my $condval  = $condvals[$i];
186
                my $nocond   = $nocondvals[$i];
187
                my $repval   = $repvals[$i];
188
                my ($result,$record)   = BatchModField($record, $field, $subfield, $action, $condval, $nocond, $repval);
189
                push @failed_actions, {action=>"$field $subfield $action ".($nocond eq "true"?"all":$condval)." $repval"} if ($result<=0);
190
            }
191
            if (@failed_actions == scalar(@fields)){
192
                $report_actions{$biblionumber}->{status}="No_Actions";
193
            }
194
            elsif (@failed_actions>0 and @failed_actions < scalar(@fields)){
195
                $report_actions{$biblionumber}->{status}="Actions_Failed";
196
                $report_actions{$biblionumber}->{failed_actions}=\@failed_actions;
197
            }
198
            elsif (@failed_actions == 0){
199
                $report_actions{$biblionumber}->{status}="OK";
200
            }
201
            ModBiblio($record, $biblionumber, $biblio->{frameworkcode});
202
        }
203
        $template->param('moddone' => 1);
204
    }
205
206
}
207
208
my @biblioinfos;
209
210
for my $biblionumber (@biblionumbers){
211
    my ($count,$biblio) = GetBiblio($biblionumber);
212
    if (defined $op){
213
        $biblio->{$report_actions{$biblionumber}->{status}}=1;
214
        $biblio->{failed_actions}=$report_actions{$biblionumber}->{failed_actions};
215
    }
216
    push @biblioinfos, $biblio;
217
}
218
219
$template->param(biblioinfos => \@biblioinfos);
220
output_html_with_http_headers $input, $cookie, $template->output;
221
exit;

Return to bug 5725