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

(-)a/C4/Biblio.pm (+101 lines)
Lines 136-141 BEGIN { Link Here
136
      &TransformHtmlToXml
136
      &TransformHtmlToXml
137
      &GetNoZebraIndexes
137
      &GetNoZebraIndexes
138
      prepare_host_field
138
      prepare_host_field
139
      &BatchModField
139
    );
140
    );
140
}
141
}
141
142
Lines 3921-3926 sub RemoveAllNsb { Link Here
3921
    return $record;
3922
    return $record;
3922
}
3923
}
3923
3924
3925
=head3 BatchModField
3926
3927
  Mod subfields in field record
3928
3929
  returns 1,$record if succeed
3930
  returns 0,$record if Action was not processed
3931
  returns -1 if no record
3932
  returns -2 if no action done on record
3933
3934
=cut
3935
3936
sub BatchModField {
3937
    my ( $record, $field, $subfield, $action, $condval, $nocond, $repval ) = @_;
3938
3939
    return -1 unless $record;
3940
    $condval=NormalizeString($condval);
3941
    my $condition=qr/$condval/;
3942
3943
    if($action eq "add"){
3944
        for my $rfield ($record->field($field)){
3945
            $rfield->add_subfields( $subfield => $repval );
3946
        }
3947
        return 1;
3948
    }elsif($action eq "addfield"){
3949
        my $new_field = MARC::Field->new($field,'','',
3950
                                         $subfield => $repval);
3951
        $record->insert_fields_ordered($new_field);
3952
        return 1;
3953
    } else {
3954
        my $done=0;
3955
        if ($field eq '000') {
3956
            my $value=$record->leader();
3957
            if ($value=~ s/$condition/$repval/){
3958
                $record->leader($repval);
3959
                $done=1;
3960
           }
3961
           if ( $nocond eq 'true'){
3962
            $record->leader($repval);
3963
            $done=1;
3964
           }
3965
        }
3966
        for my $rfield ($record->field($field)) {
3967
            if ($subfield && $subfield ne "@"){
3968
                my @subfields = $rfield->subfields();
3969
                my @subfields_to_add;
3970
                foreach my $subf (@subfields) {
3971
                    if ($subf->[0] eq $subfield){
3972
                        $subf->[1]=NormalizeString($subf->[1]);
3973
                        if ( $action eq "mod" ) {
3974
                            if ( $nocond ne "true" && $subf->[1] =~ s/$condition/$repval/) {
3975
                                $done=1;
3976
                            }
3977
                            if ($nocond eq "true"){
3978
                                $subf->[1] = $repval;
3979
                                $done=1;
3980
                            }
3981
                        } elsif ( $action eq "del" ) {
3982
                            if ( $subf->[1] =~ m/$condition/ || $nocond eq "true" ) {
3983
                                $done=1;
3984
                                next;
3985
                            }
3986
                        }
3987
                    }
3988
                    push @subfields_to_add,@$subf;
3989
                }
3990
                if ($done){
3991
                    if (@subfields_to_add){
3992
                        $rfield->replace_with(MARC::Field->new($rfield->tag,$rfield->indicator(1),$rfield->indicator(2),@subfields_to_add));
3993
                    }
3994
                    else {
3995
                        my $count= $record->delete_field($rfield);
3996
                    }
3997
                }
3998
            }
3999
            else {
4000
                if ($action eq "del"){
4001
                    my $count=$record->delete_field($rfield);
4002
                    $done=1;
4003
                }
4004
                else {
4005
                    if ($field < 10){
4006
                       my $value=$record->field($field)->data();
4007
                       if ($value=~ s/$condition/$repval/){
4008
                            $record->field($field)->update($value);
4009
                            $done=1;
4010
4011
                       }
4012
                       if ( $nocond eq 'true'){
4013
                        $record->field($field)->update($repval);
4014
                        $done=1;
4015
                       }
4016
                    }
4017
                }
4018
            }
4019
        }
4020
        return ($done,$record);
4021
    }
4022
    return -2;
4023
}
4024
3924
1;
4025
1;
3925
4026
3926
4027
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +7 lines)
Lines 4369-4375 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4369
4369
4370
$DBversion = "3.05.00.004";
4370
$DBversion = "3.05.00.004";
4371
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4371
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4372
    $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');");
4372
    $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')");
4373
    print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n";
4373
    print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n";
4374
    SetVersion($DBversion);    
4374
    SetVersion($DBversion);    
4375
}
4375
}
Lines 4440-4445 $DBversion = "3.05.00.010"; Link Here
4440
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4440
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4441
    $dbh->do("CREATE INDEX priorityfoundidx ON reserves (priority,found)");
4441
    $dbh->do("CREATE INDEX priorityfoundidx ON reserves (priority,found)");
4442
    print "Create an index on reserves to speed up holds awaiting pickup report bug 5866\n";
4442
    print "Create an index on reserves to speed up holds awaiting pickup report bug 5866\n";
4443
}
4444
4445
$DBversion = "3.05.00.XXX";
4446
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4447
    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchedit', 'Batch editing biblios')");
4448
    print "Upgrade to $DBversion done (batch edit permission)\n";
4443
    SetVersion($DBversion);
4449
    SetVersion($DBversion);
4444
}
4450
}
4445
4451
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/basket.js (+6 lines)
Lines 442-445 $(document).ready(function(){ Link Here
442
	if(basketcount){ updateBasket(basketcount); }
442
	if(basketcount){ updateBasket(basketcount); }
443
});
443
});
444
444
445
function batchEdit(){
446
    var valCookie = readCookie(nameCookie);
447
    var strCookie = nameParam + "=" + valCookie;
445
448
449
    var loc = CGIBIN + "tools/batchedit.pl?" + strCookie;
450
    window.opener.location = loc;
451
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt (+7 lines)
Lines 93-98 function placeHold () { Link Here
93
        [% 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 %]
93
        [% 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 %]
94
	    </span></span>
94
	    </span></span>
95
	</li>
95
	</li>
96
    [% IF ( CAN_user_tools_batchedit ) %]
97
    <li>
98
        <span id="batchedit" class="yui-button yui-link-button"><span class="first-child">
99
        <a class="batchedit" href="basket.pl" onclick="batchEdit(); return false;">Batch Edit</a>
100
        </span></span>
101
    </li>
102
    [% END %]
96
	<li>
103
	<li>
97
	    <span id="receive" class="yui-button yui-link-button"><span class="first-child">
104
	    <span id="receive" class="yui-button yui-link-button"><span class="first-child">
98
		<a class="send" href="basket.pl" onclick="sendBasket(); return false;">Send</a>
105
		<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 112-117 Link Here
112
    <dd>Modify items in a batch</dd>
112
    <dd>Modify items in a batch</dd>
113
    [% END %]
113
    [% END %]
114
    
114
    
115
    [% IF ( CAN_user_tools_batchedit ) %]
116
    <dt><a href="/cgi-bin/koha/tools/batchedit.pl">Batch biblio modification</a></dt>
117
    <dd>Modify biblios in a batch</dd>
118
    [% END %]
119
115
    [% IF ( CAN_user_tools_export_catalog ) %]
120
    [% IF ( CAN_user_tools_export_catalog ) %]
116
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt>
121
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt>
117
    <dd>Export bibliographic, holdings, and authority records</dd>
122
    <dd>Export bibliographic, holdings, and authority records</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