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

(-)a/C4/Biblio.pm (-12 / +159 lines)
Lines 93-98 BEGIN { Link Here
93
      &ModBiblio
93
      &ModBiblio
94
      &ModBiblioframework
94
      &ModBiblioframework
95
      &ModZebra
95
      &ModZebra
96
97
      &BatchModField
96
    );
98
    );
97
99
98
    # To delete something
100
    # To delete something
Lines 376-382 sub ModBiblioframework { Link Here
376
378
377
=head2 DelBiblio
379
=head2 DelBiblio
378
380
379
  my $error = &DelBiblio($dbh,$biblionumber);
381
  my $error = &DelBiblio($biblionumber);
380
382
381
Exported function (core API) for deleting a biblio in koha.
383
Exported function (core API) for deleting a biblio in koha.
382
Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
384
Deletes biblio record from Zebra and Koha tables (biblio,biblioitems,items)
Lines 1046-1054 The MARC record contains both biblio & item data. Link Here
1046
1048
1047
sub GetMarcBiblio {
1049
sub GetMarcBiblio {
1048
    my $biblionumber = shift;
1050
    my $biblionumber = shift;
1051
    my $deletedtable = shift;
1049
    my $dbh          = C4::Context->dbh;
1052
    my $dbh          = C4::Context->dbh;
1050
    my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1053
    my $strsth       = qq{SELECT marcxml FROM biblioitems WHERE biblionumber=?};
1051
    $sth->execute($biblionumber);
1054
    $strsth .= qq{UNION SELECT marcxml FROM deletedbiblioitems WHERE biblionumber=?} if $deletedtable;
1055
    my $sth = $dbh->prepare($strsth);
1056
    my @params=($biblionumber);
1057
    push @params, $biblionumber if ($deletedtable);
1058
    $sth->execute(@params);
1052
    my $row     = $sth->fetchrow_hashref;
1059
    my $row     = $sth->fetchrow_hashref;
1053
    my $marcxml = StripNonXmlChars( $row->{'marcxml'} );
1060
    my $marcxml = StripNonXmlChars( $row->{'marcxml'} );
1054
    MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') );
1061
    MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') );
Lines 1113-1118 sub GetCOinSBiblio { Link Here
1113
    my $isbn      = '';
1120
    my $isbn      = '';
1114
    my $issn      = '';
1121
    my $issn      = '';
1115
    my $publisher = '';
1122
    my $publisher = '';
1123
    my $place     = '';
1124
    my $tpages    = '';
1116
1125
1117
    if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
1126
    if ( C4::Context->preference("marcflavour") eq "UNIMARC" ) {
1118
        my $fmts6;
1127
        my $fmts6;
Lines 1159-1182 sub GetCOinSBiblio { Link Here
1159
        $genre = ( $mtx eq 'dc' ) ? "&rft.type=$genre" : "&rft.genre=$genre";
1168
        $genre = ( $mtx eq 'dc' ) ? "&rft.type=$genre" : "&rft.genre=$genre";
1160
1169
1161
        # Setting datas
1170
        # Setting datas
1162
        $aulast  = $record->subfield( '700', 'a' );
1171
1163
        $aufirst = $record->subfield( '700', 'b' );
1172
	# authors
1164
        $oauthors = "&rft.au=$aufirst $aulast";
1173
        $aulast  = $record->subfield( '700', 'a' ) || '';
1174
        $aufirst = $record->subfield( '700', 'b' ) || '';
1175
1176
	foreach my $field (qw/700 701/) {
1177
	    my $author = '';
1178
	    $author = $record->subfield($field, 'a') || '';
1179
	    $author .= ", "  . $record->subfield($field, 'b')              if ($author and $record->subfield($field, 'b'));
1180
	    $author .= " - " . join(' - ', $record->subfield($field, '4')) if ($record->subfield($field, '4'));
1181
	    $author .= " ("  . $record->subfield($field, 'f') . ")"        if ($record->subfield($field, 'f'));
1182
1183
	    $oauthors .= "&rft.au=$author" if ($author);
1184
	}
1185
1186
	foreach my $field (qw/710 711/) {
1187
	    my $author = '';
1188
	    $author = $record->subfield($field, 'a') || '';
1189
	    $author .= ", "  . $record->subfield($field, 'b')              if ($author and $record->subfield($field, 'b'));
1190
	    $author .= " - " . join(' - ', $record->subfield($field, '4')) if ($record->subfield($field, '4'));
1191
	    $author .= " ("  . $record->subfield($field, 'c') . ")"        if ($record->subfield($field, 'c'));
1192
1193
	    $oauthors .= "&rft.au=$author" if ($author);
1194
	}
1195
1165
1196
1166
        # others authors
1197
        # others authors
1167
        if ( $record->field('200') ) {
1198
        if ( $record->field('200') ) {
1199
            for my $au ( $record->field('200')->subfield('f') ) {
1200
                $oauthors .= "&rft.au=$au";
1201
            }
1168
            for my $au ( $record->field('200')->subfield('g') ) {
1202
            for my $au ( $record->field('200')->subfield('g') ) {
1169
                $oauthors .= "&rft.au=$au";
1203
                $oauthors .= "&rft.au=$au";
1170
            }
1204
            }
1205
1171
        }
1206
        }
1207
1208
	# place
1209
	$place = join(" - ", $record->subfield('210', 'a'));
1210
	$place = "&rtf.place=$place" if ($place);
1211
1212
	# tpages
1213
	my $i = 0;
1214
	foreach my $field ($record->field('215')) {
1215
		$tpages .= " | " if ($i > 0);
1216
		$tpages .= join(" - ", $field->subfield('a'));
1217
		$tpages .= join(" ; ", $field->subfield('d'));
1218
		$tpages .= join(" + ", $field->subfield('e'));
1219
		$i++;
1220
	}
1221
	$tpages = "&rtf.tpages=$tpages" if ($tpages);
1222
1223
	# title
1224
	my $btitle = join(' ; ', $record->subfield('200', 'a'));
1225
	$btitle .= " : " . join(' : ', $record->subfield('200', 'e')) if ($record->subfield('200', 'e'));
1226
1172
        $title =
1227
        $title =
1173
          ( $mtx eq 'dc' )
1228
          ( $mtx eq 'dc' )
1174
          ? "&rft.title=" . $record->subfield( '200', 'a' )
1229
          ? "&rft.title=" . $record->subfield( '200', 'a' )
1175
          : "&rft.title=" . $record->subfield( '200', 'a' ) . "&rft.btitle=" . $record->subfield( '200', 'a' );
1230
          : "&rft.title=" . $record->subfield( '200', 'a' ) . "&rft.btitle=" . $btitle;
1176
        $pubyear   = $record->subfield( '210', 'd' );
1231
        $pubyear   = $record->subfield( '210', 'd' ) || '';
1177
        $publisher = $record->subfield( '210', 'c' );
1232
        $publisher = $record->subfield( '210', 'c' ) || '';
1178
        $isbn      = $record->subfield( '010', 'a' );
1233
        $isbn      = $record->subfield( '010', 'a' ) || '';
1179
        $issn      = $record->subfield( '011', 'a' );
1234
        $issn      = $record->subfield( '011', 'a' ) || '';
1180
    } else {
1235
    } else {
1181
1236
1182
        # MARC21 need some improve
1237
        # MARC21 need some improve
Lines 1205-1211 sub GetCOinSBiblio { Link Here
1205
1260
1206
    }
1261
    }
1207
    my $coins_value =
1262
    my $coins_value =
1208
"ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3A$mtx$genre$title&rft.isbn=$isbn&rft.issn=$issn&rft.aulast=$aulast&rft.aufirst=$aufirst$oauthors&rft.pub=$publisher&rft.date=$pubyear";
1263
"ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3A$mtx$genre$title&rft.isbn=$isbn&rft.issn=$issn&rft.aulast=$aulast&rft.aufirst=$aufirst$oauthors&rft.pub=$publisher&rft.date=$pubyear$place$tpages";
1209
    $coins_value =~ s/(\ |&[^a])/\+/g;
1264
    $coins_value =~ s/(\ |&[^a])/\+/g;
1210
    $coins_value =~ s/\"/\&quot\;/g;
1265
    $coins_value =~ s/\"/\&quot\;/g;
1211
1266
Lines 1750-1755 sub TransformHtmlToXml { Link Here
1750
        @$values[$i] =~ s/>/>/g;
1805
        @$values[$i] =~ s/>/>/g;
1751
        @$values[$i] =~ s/"/"/g;
1806
        @$values[$i] =~ s/"/"/g;
1752
        @$values[$i] =~ s/'/'/g;
1807
        @$values[$i] =~ s/'/'/g;
1808
	@$values[$i] = NormalizeString(@$values[$i]);
1753
1809
1754
        #         if ( !utf8::is_utf8( @$values[$i] ) ) {
1810
        #         if ( !utf8::is_utf8( @$values[$i] ) ) {
1755
        #             utf8::decode( @$values[$i] );
1811
        #             utf8::decode( @$values[$i] );
Lines 2313-2319 sub PrepareItemrecordDisplay { Link Here
2313
                                push @authorised_values, $branchcode;
2369
                                push @authorised_values, $branchcode;
2314
                                $authorised_lib{$branchcode} = $branchname;
2370
                                $authorised_lib{$branchcode} = $branchname;
2315
                            }
2371
                            }
2372
			    $defaultvalue = C4::Context->userenv->{branch};
2316
                        }
2373
                        }
2374
                        $defaultvalue = C4::Context->userenv->{branch};
2317
2375
2318
                        #----- itemtypes
2376
                        #----- itemtypes
2319
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
2377
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
Lines 3461-3466 sub get_biblio_authorised_values { Link Here
3461
    return $authorised_values;
3519
    return $authorised_values;
3462
}
3520
}
3463
3521
3522
=head3 BatchModField
3523
3524
  Mod subfields in field record
3525
3526
  returns 1,$record if succeed
3527
  returns 0,$record if Action was not processed
3528
  returns -1 if no record
3529
  returns -2 if no action done on record
3530
3531
=cut
3532
3533
sub BatchModField {
3534
    my ( $record, $field, $subfield, $action, $condval, $nocond, $repval ) = @_;
3535
3536
    return -1 unless $record;
3537
    $condval=NormalizeString($condval);
3538
    my $condition=qr/$condval/;
3539
3540
    if($action eq "add"){
3541
        for my $rfield ($record->field($field)){
3542
            $rfield->add_subfields( $subfield => $repval );
3543
        }
3544
        return 1;
3545
    }elsif($action eq "addfield"){
3546
        my $new_field = MARC::Field->new($field,'','',
3547
                                         $subfield => $repval);
3548
        $record->insert_fields_ordered($new_field);
3549
        return 1;
3550
    } else {
3551
        my $done=0;
3552
        for my $rfield ($record->field($field)) {
3553
            if ($subfield && $subfield ne "@"){
3554
                my @subfields = $rfield->subfields();
3555
                my @subfields_to_add;
3556
            foreach my $subf (@subfields) {
3557
                    if ($subf->[0] eq $subfield){
3558
                        $subf->[1]=NormalizeString($subf->[1]);
3559
                        if ( $action eq "mod" ) {
3560
                            if ( $nocond ne "true" && $subf->[1] =~ s/$condition/$repval/) {
3561
                                $done=1;
3562
                            }
3563
                            if ($nocond eq "true"){
3564
                                $subf->[1] = $repval;
3565
                                $done=1;
3566
                    }
3567
                } elsif ( $action eq "del" ) {
3568
                            if ( $subf->[1] =~ m/$condition/ || $nocond eq "true" ) {
3569
                                $done=1;
3570
                                next;
3571
                            }
3572
                        }
3573
                    }
3574
                    push @subfields_to_add,@$subf;
3575
        }
3576
                if ($done){
3577
                    if (@subfields_to_add){
3578
                        $rfield->replace_with(MARC::Field->new($rfield->tag,$rfield->indicator(1),$rfield->indicator(2),@subfields_to_add));
3579
    }
3580
                    else {
3581
                        my $count= $record->delete_field($rfield);
3582
                    }
3583
                }
3584
            }
3585
            else {
3586
                if ($action eq "del"){
3587
                    my $count=$record->delete_field($rfield);
3588
                    $done=1;
3589
                }
3590
                else {
3591
                    if ($field < 10){
3592
                       my $value=$record->field($field)->data();
3593
                       if ($value=~ s/$condition/$repval/){
3594
                        $record->field($field)->update($value);
3595
                        $done=1;
3596
3597
                       }
3598
                       if ( $nocond eq 'true'){
3599
                        $record->field($field)->update($repval);
3600
                        $done=1;
3601
                       }
3602
                    }
3603
                }
3604
            }
3605
        }
3606
        return ($done,$record);
3607
    }
3608
    return -2;
3609
}
3610
3464
1;
3611
1;
3465
3612
3466
__END__
3613
__END__
(-)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.tmpl (+5 lines)
Lines 86-91 function placeHold () { Link Here
86
		<!-- TMPL_IF NAME="verbose" --><a href="basket.pl" class="brief" onclick="showLess(); return false;">Brief Display</a><!-- TMPL_ELSE --><a href="basket.pl" class="detail" onclick="showMore(); return false;">More Details</a><!-- /TMPL_IF -->
86
		<!-- TMPL_IF NAME="verbose" --><a href="basket.pl" class="brief" onclick="showLess(); return false;">Brief Display</a><!-- TMPL_ELSE --><a href="basket.pl" class="detail" onclick="showMore(); return false;">More Details</a><!-- /TMPL_IF -->
87
	    </span></span>
87
	    </span></span>
88
	</li>
88
	</li>
89
    <li>
90
        <span id="batchedit" class="yui-button yui-link-button"><span class="first-child">
91
        <a class="batchedit" href="basket.pl" onclick="batchEdit(); return false;">Batch Edit</a>
92
        </span></span>
93
    </li>
89
	<li>
94
	<li>
90
	    <span id="receive" class="yui-button yui-link-button"><span class="first-child">
95
	    <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>
96
		<a class="send" href="basket.pl" onclick="sendBasket(); return false;">Send</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchedit.tmpl (+231 lines)
Line 0 Link Here
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2
<title>Koha &rsaquo; Tools &rsaquo; Batch Deletion of Items</title>
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4
5
<!-- TMPL_UNLESS NAME="modsuccess" -->
6
7
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
8
<script type="text/JavaScript" language="JavaScript">
9
//<![CDATA[
10
     var CGIBIN = "/cgi-bin/koha/";
11
12
     function fieldChanged(){
13
        var field = $('#fieldchoice').val();
14
        $.ajax({
15
		url: CGIBIN + 'tools/batchedit.pl?field=' + field,
16
		dataType: 'json',
17
            success: function(data){
18
		$("#subfieldchoice option").remove();
19
20
		    var subfield = $('#subfieldchoice');
21
			$("<option>").attr("value", "@")
22
                                 .text( _('Whole field'))
23
                                 .appendTo('#subfieldchoice');
24
                for( var i=0; i < data.length ; i++){
25
			$("<option>").attr("value", data[i].subfield)
26
                                 .text(data[i].subfield)
27
                                 .appendTo('#subfieldchoice');
28
                }
29
                subfieldChanged();
30
            }
31
        });
32
     }
33
34
     function subfieldChanged(){
35
        var field    = $('#fieldchoice').val();
36
        var subfield = $('#subfieldchoice').val();
37
        $.ajax({
38
		url: CGIBIN + 'tools/batchedit.pl?field=' + field + '&subfield=' + subfield,
39
		dataType: 'json',
40
            success: function(data){
41
42
		    if( data.length > 0) {
43
			$("#condvaltd").html('<select name="condvalchoice" id="condvalchoice" />');
44
			$("<option>").attr("value", "")
45
                        .text("")
46
                        .appendTo('#condvalchoice');
47
			$("#repvaltd" ).html('<select name="repvalchoice" id="repvalchoice" />'  );
48
                    $("<option>").attr("value", "")
49
                        .text("")
50
                        .appendTo('#repvalchoice');
51
52
                    for( var i=0; i < data.length ; i++){
53
			$("<option>").attr("value", data[i].code)
54
                            .text(data[i].value)
55
                            .appendTo('#repvalchoice');
56
			$("<option>").attr("value", data[i].code)
57
                            .text(data[i].value)
58
                            .appendTo('#condvalchoice');
59
                    }
60
		    }else{
61
                    $("#condvaltd").html('<input type="text" name="condvalchoice" id="condvalchoice" />');
62
                    $("#repvaltd").html('<input type="text" name="repvalchoice"  id="repvalchoice" />');
63
		    }
64
                $('<input type="checkbox" id="nocond" name="nocond" value="nocond" onClick="$(\'#condvalchoice\').attr(\'disabled\', ! $(\'#condvalchoice\').attr(\'disabled\') ) ">All</input>').appendTo("#condvaltd");
65
            }
66
        });
67
68
     }
69
70
     function addRule(){
71
        var actionlabel = {
72
                mod: _('Modify'),
73
                del: _('Delete'),
74
                add: _('Create')
75
                };
76
        var repvallabel  = $('#repvalchoice :selected').text()  || $("#repvalchoice").val();
77
78
        var field    = $('#fieldchoice').val();
79
        var subfield = $('#subfieldchoice').val();
80
        var action   = $('#actionchoice').val();
81
        var nocond   = $('#nocond').attr('checked')||(! $('#condvalchoice').val().length);
82
83
        if( ! nocond ) {
84
            var condval  = $('#condvalchoice').val();
85
            var condvallabel = $('#condvalchoice :selected').text() || $("#condvalchoice").val();
86
        }else{
87
            var condvallabel = _("No condition");
88
        }
89
        var repval   = $('#repvalchoice').val();
90
91
        var tmpl = "<tr>"
92
                + '<td><input type="hidden" name="field" value="'    + field + '" />'    + field               + '</td>'
93
                + '<td><input type="hidden" name="subfield" value="' + subfield + '" />' + subfield            + '</td>'
94
                + '<td><input type="hidden" name="action" value="'   + action + '" />'   + actionlabel[action] + '</td>'
95
                + '<td><input type="hidden" name="condval" value="'  + condval + '" />'
96
                    + condvallabel
97
                    + '<input type="hidden" name="nocondval" value="' + nocond + '" />'
98
                + '</td>'
99
100
                + '<td><input type="hidden" name="repval" value="'   + repval + '" />'   + repvallabel         + '</td>'
101
                + '<td><input type="button" value="Delete" onclick="deleteRule(this)" /></td>'
102
            + '</tr>';
103
        $('#rulestable').append(tmpl);
104
105
     }
106
107
     function deleteRule(button){
108
        $(button).parent().parent().remove();
109
        return false;
110
     }
111
112
113
//]]>
114
</script>
115
<!-- /TMPL_UNLESS -->
116
</head>
117
<body>
118
<!-- TMPL_INCLUDE NAME="header.inc" -->
119
<!-- TMPL_INCLUDE NAME="cat-search.inc"-->
120
<div id="doc3" class="yui-t2">
121
    <div id="bd">
122
        <div id="yui-main">
123
            <div class="yui-b">
124
125
<form method="post" enctype="multipart/form-data">
126
<!-- TMPL_IF NAME="inputform" -->
127
<h2>Batch records modification</h2>
128
    <fieldset class="rows">
129
	<legend>Use a file</legend>
130
	<ol>
131
	    <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
132
	</ol>
133
    </fieldset>
134
    <fieldset class="rows">
135
	<legend>Or enter records one by one</legend>
136
	<ol>
137
	    <li>
138
		<label for="recordslist">Records numbers list (one number per line): </label>
139
		<textarea rows="10" cols="30" id="recordslist" name="recordslist"></textarea>
140
	    </li>
141
	</ol>
142
    </fieldset>
143
<!-- TMPL_ELSE -->
144
<h2>List of records:</h2>
145
<table id="bibliolist">
146
    <thead>
147
        <tr>
148
            <th>Biblionumber</th><th>Title</th><th>Author</th><!-- TMPL_IF Name="moddone"--> <th>Status</th><!-- /TMPL_IF -->
149
        </tr>
150
    </thead>
151
    <!-- TMPL_LOOP NAME="biblioinfos" -->
152
        <tr>
153
            <td><!-- TMPL_VAR NAME="biblionumber" --></td>
154
            <td><!-- TMPL_VAR NAME="title" --></td>
155
            <td><!-- TMPL_VAR NAME="author" --></td>
156
            <!-- TMPL_IF Name="moddone"-->
157
            <!-- TMPL_IF NAME="OK" -->
158
            <td>
159
            <!--TMPL_ELSE-->
160
            <td class="problem">
161
            <!--/TMPL_IF-->
162
            <!-- TMPL_IF NAME="OK" -->OK<!--/TMPL_IF-->
163
            <!-- TMPL_IF NAME="No_Actions" -->Nothing done<!--/TMPL_IF-->
164
            <!-- TMPL_IF NAME="Actions_Failed" -->Some Actions failed. List Follow : <ul><!-- TMPL_LOOP NAME="failed_actions" --><li><!-- TMPL_VAR NAME="action" --></li><!--/TMPL_LOOP --></ul><!--/TMPL_IF-->
165
            </td><!-- /TMPL_IF -->
166
        </tr>
167
    <!-- /TMPL_LOOP -->
168
</table>
169
<!-- /TMPL_IF -->
170
171
<!-- TMPL_IF NAME="moddone" -->
172
    <div class="dialog alert">All operations processed</div>
173
<!-- TMPL_ELSE -->
174
175
<fieldset>
176
<h2>Modification rules:</h2>
177
<input type="submit" value="Submit" />
178
<input type="hidden" name="op" value="do" />
179
<input type="hidden" name="bib_list" value="<!-- TMPL_VAR NAME="bib_list" -->" />
180
<table id="rulestable">
181
    <thead>
182
        <tr>
183
            <th>Field</th><th>Subfield</th><th>Action</th><th>Condition Value</th><th>Value</th><th>&nbsp;</th>
184
        </tr>
185
    </thead>
186
        <tr>
187
            <td>
188
                <select name="fieldchoice" id="fieldchoice" onchange="fieldChanged();">
189
<!-- TMPL_LOOP NAME="marcfields" -->
190
                    <option value="<!-- TMPL_VAR NAME="tag" -->"><!-- TMPL_VAR NAME="tag" --></option>
191
<!-- /TMPL_LOOP -->
192
                </select>
193
            </td>
194
            <td>
195
                <select name="subfieldchoice" id="subfieldchoice" onchange="subfieldChanged();">
196
197
                </select>
198
            </td>
199
            <td>
200
                <select name="actionchoice" id="actionchoice">
201
                    <option value="mod">Modify subfield</option>
202
                    <option value="add">Create subfield</option>
203
                    <option value="addfield">Create field and subfield</option>
204
                    <option value="del">Delete subfield</option>
205
                </select>
206
            </td>
207
            <td id="condvaltd">
208
                <input type="text" name="condvalchoice" id="condvalchoice" />
209
                <input type="checkbox" id="nocond" name="nocond" value="nocond" onClick="$('#condvalchoice').attr('disabled', ! $('#condvalchoice').attr('disabled') ) ">All</input>
210
            </td>
211
            <td id="repvaltd">
212
                <input type="text" name="repvalchoice" id="repvalchoice" />
213
            </td>
214
            <td><input type="button" value="Add" onclick="addRule();" /></td>
215
        </tr>
216
    </thead>
217
218
<!-- TMPL_LOOP NAME="marcfields" -->
219
220
<!-- /TMPL_LOOP -->
221
</table>
222
<input type="submit" value="Submit" />
223
</fieldset>
224
</form>
225
<!-- /TMPL_IF -->
226
            </div>
227
        </div>
228
    </div>
229
</div>
230
</body>
231
</html>
(-)a/tools/batchedit.pl (-1 / +222 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
if ($filefh) {
41
    while ( my $biblionumber = <$filefh> ) {
42
        $biblionumber =~ s/[\r\n]*$//g;
43
        push @biblionumbers, $biblionumber if $biblionumber;
44
    }
45
} elsif ($recordslist) {
46
    push @biblionumbers, split( /\s\n/, $recordslist );
47
} elsif ($bib_list) {
48
    push @biblionumbers, split('/', $bib_list);
49
}
50
51
my $op            = $input->param('op');
52
my ($template, $loggedinuser, $cookie);
53
54
my $frameworkcode="";
55
my $tagslib = &GetMarcStructure(1,$frameworkcode);
56
my %report_actions;
57
58
if($input->param('field') and not defined $op){
59
    ($template, $loggedinuser, $cookie)
60
        = get_template_and_user({template_name => "acqui/ajax.tmpl",
61
                 query => $input,
62
                 type => "intranet",
63
                 authnotrequired => 0,
64
                 flagsrequired => "batchedit",
65
        });
66
67
68
    my $tag      = $input->param('field');
69
    my $subfield = $input->param('subfield');
70
71
    if($input->param('subfield')){
72
        my $branches = GetBranchesLoop();
73
74
        my @authorised_values;
75
        if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
76
             if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
77
                foreach my $thisbranch (@$branches) {
78
                    push @authorised_values, {
79
                            code => $thisbranch->{value},
80
                            value => $thisbranch->{branchname},
81
                        };
82
                    # $value = $thisbranch->{value} if $thisbranch->{selected};
83
                }
84
             }elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
85
                 my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
86
                 $sth->execute();
87
                 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
88
                    push @authorised_values, {
89
                        code => $itemtype,
90
                        value => $description,
91
                    };
92
                 }
93
94
            }else {
95
                  # Getting the fields where the item location is
96
                  my ($location_field, $location_subfield) = GetMarcFromKohaField('items.location', $frameworkcode);
97
98
                  # Getting the name of the authorised values' category for item location
99
                  my $item_location_category = $tagslib->{$location_field}->{$location_subfield}->{'authorised_value'};
100
		      # Are we dealing with item location ?
101
                  my $item_location = ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) ? 1 : 0;
102
103
                  # If so, we sort by authorised_value, else by libelle
104
                  my $orderby = $item_location ? 'authorised_value' : 'lib';
105
106
                  my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY $orderby");
107
108
                  $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value});
109
110
111
                  while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
112
                    push @authorised_values, {
113
                        code => $value,
114
                        value => ($item_location) ? $value . " - " . $lib : $lib,
115
                    };
116
117
                  }
118
            }
119
        }
120
      $template->param('return' => to_json(\@authorised_values));
121
    }else{
122
        my @modifiablesubf;
123
124
        foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
125
            next if subfield_is_koha_internal_p($subfield);
126
            next if $subfield eq "@";
127
            next if ($tagslib->{$tag}->{$subfield}->{'tab'} eq "10");
128
            my %subfield_data;
129
            $subfield_data{subfield} = $subfield;
130
            push @modifiablesubf, \%subfield_data;
131
        }
132
        $template->param('return' => to_json(\@modifiablesubf));
133
    }
134
135
136
    output_html_with_http_headers $input, $cookie, $template->output;
137
    exit;
138
}else{
139
    ($template, $loggedinuser, $cookie)
140
            = get_template_and_user({template_name => "tools/batchedit.tmpl",
141
                     query => $input,
142
                     type => "intranet",
143
                     authnotrequired => 0,
144
                     flagsrequired => "batchedit",
145
                     });
146
147
    $template->param( inputform => 1, ) unless @biblionumbers;
148
149
    if(!defined $op) {
150
        my @modifiablefields;
151
152
        foreach my $tag (sort keys %{$tagslib}) {
153
            my %subfield_data;
154
            foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
155
                next if $subfield_data{tag};
156
                next if subfield_is_koha_internal_p($subfield);
157
                next if ($tagslib->{$tag}->{$subfield}->{'tab'} eq "10");
158
159
                $subfield_data{tag}      = $tag;
160
161
                push @modifiablefields, \%subfield_data;
162
            }
163
        }
164
165
        $template->param( marcfields  => \@modifiablefields,
166
                          bib_list    => $input->param('bib_list'),
167
                         );
168
169
    }else{
170
        my @fields     = $input->param('field');
171
        my @subfields  = $input->param('subfield');
172
        my @actions    = $input->param('action');
173
        my @condvals   = $input->param('condval');
174
        my @nocondvals = $input->param('nocondval');
175
        my @repvals    = $input->param('repval');
176
        foreach my $biblionumber ( @biblionumbers ){
177
            my $record = GetMarcBiblio($biblionumber);
178
            my $biblio = GetBiblio($biblionumber);
179
            my $report = 0;
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
189
                my ($result,$record)   = BatchModField($record, $field, $subfield, $action, $condval, $nocond, $repval);
190
                push @failed_actions, {action=>"$field $subfield $action ".($nocond eq "true"?"all":$condval)." $repval"} if ($result<=0);
191
            }
192
            if (@failed_actions == scalar(@fields)){
193
                $report_actions{$biblionumber}->{status}="No_Actions";
194
            }
195
            elsif (@failed_actions>0 and @failed_actions < scalar(@fields)){
196
                $report_actions{$biblionumber}->{status}="Actions_Failed";
197
                $report_actions{$biblionumber}->{failed_actions}=\@failed_actions;
198
            }
199
            elsif (@failed_actions == 0){
200
                $report_actions{$biblionumber}->{status}="OK";
201
            }
202
            ModBiblio($record, $biblionumber, $biblio->{frameworkcode}) unless ($report);
203
        }
204
        $template->param('moddone' => 1);
205
    }
206
207
}
208
209
my @biblioinfos;
210
211
for my $biblionumber (@biblionumbers){
212
    my $biblio = GetBiblio($biblionumber);
213
    if (defined $op){
214
        $biblio->{$report_actions{$biblionumber}->{status}}=1;
215
        $biblio->{failed_actions}=$report_actions{$biblionumber}->{failed_actions};
216
    }
217
    push @biblioinfos, $biblio;
218
}
219
220
$template->param(biblioinfos => \@biblioinfos);
221
output_html_with_http_headers $input, $cookie, $template->output;
222
exit;

Return to bug 5725