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

(-)a/cataloguing/addbiblio.pl (-1 / +2 lines)
Lines 987-993 $template->param( Link Here
987
    popup => $mode,
987
    popup => $mode,
988
    frameworkcode => $frameworkcode,
988
    frameworkcode => $frameworkcode,
989
    itemtype => $frameworkcode,
989
    itemtype => $frameworkcode,
990
    borrowernumber => $loggedinuser, 
990
    borrowernumber => $loggedinuser,
991
    RequireValidISBN => C4::Context->preference("RequireValidISBN")
991
);
992
);
992
993
993
output_html_with_http_headers $input, $cookie, $template->output;
994
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 419-421 INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) V Link Here
419
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacItemLocation','callnum','Show the shelving location of items in the opac','callnum|ccode|location','Choice');
419
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacItemLocation','callnum','Show the shelving location of items in the opac','callnum|ccode|location','Choice');
420
INSERT INTO systempreferences (variable,value,explanation,options,type)  VALUES('TrackClicks','0','Track links clicked',NULL,'Integer');
420
INSERT INTO systempreferences (variable,value,explanation,options,type)  VALUES('TrackClicks','0','Track links clicked',NULL,'Integer');
421
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('PatronSelfRegistrationAdditionalInstructions','','A free text field to display additional instructions to newly self registered patrons.','','free');
421
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('PatronSelfRegistrationAdditionalInstructions','','A free text field to display additional instructions to newly self registered patrons.','','free');
422
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RequireValidISBN',0,'Require a valid ISBN',NULL,'YesNo');
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 6512-6517 if ( CheckVersion($DBversion) ) { Link Here
6512
    SetVersion($DBversion);
6512
    SetVersion($DBversion);
6513
}
6513
}
6514
6514
6515
$DBversion = "3.11.00.XXX";
6516
if ( CheckVersion($DBversion) ) {
6517
    $dbh->do(q{
6518
        INSERT INTO systempreferences (variable,value,explanation,options,type)
6519
        VALUES('RequireValidISBN', '0', 'Require a valid ISBN',NULL,'YesNo')
6520
    });
6521
   print "Upgrade to $DBversion done (Bug 906: ISBN Check)\n";
6522
   SetVersion($DBversion);
6523
}
6524
6515
=head1 FUNCTIONS
6525
=head1 FUNCTIONS
6516
6526
6517
=head2 TableExists($table)
6527
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+6 lines)
Lines 109-114 Cataloging: Link Here
109
            - pref: UNIMARCField100Language
109
            - pref: UNIMARCField100Language
110
              class: short
110
              class: short
111
            - as default language in the UNIMARC field 100 when creating a new record or in the field plugin.
111
            - as default language in the UNIMARC field 100 when creating a new record or in the field plugin.
112
        -
113
            - pref: RequireValidISBN
114
              choices:
115
                  yes: Require
116
                  no: Don't require
117
            - a valid ISBN.
112
    Display:
118
    Display:
113
        -
119
        -
114
            - 'Separate multiple displayed authors, series or subjects with '
120
            - 'Separate multiple displayed authors, series or subjects with '
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt (-5 / +100 lines)
Lines 135-140 function showMARCdocLinks() { Link Here
135
	$.cookie("marcdocs_[% borrowernumber %]",'true', { path: "/", expires: 365 });
135
	$.cookie("marcdocs_[% borrowernumber %]",'true', { path: "/", expires: 365 });
136
}
136
}
137
137
138
/*
139
 * Functions to check ISBN validity
140
 */
141
142
function _NormalizeISBN(isbn) {
143
    // remove non-word characters
144
    var normalized_isbn = isbn.replace(/\W|_/g,'');
145
    // we want upper-case 'X'
146
    return normalized_isbn.toUpperCase();
147
}
148
149
function _CheckISBNChecksum10(isbn) {
150
151
    var sum = 0;
152
    var i,r;
153
154
    if ( isbn.match(/\d{10}|^\d{9}X$/) ) {
155
        // its a 10 digit string, it might end with X
156
        for ( i=0; i<9; i++ ) {
157
            sum += (i+1) * parseInt(isbn[i],10);
158
        }
159
        r = sum % 11;
160
        if ( r == 10 && isbn[9] == 'X' ||
161
             r == isbn[9] ) {
162
            return isbn;
163
        }
164
    }
165
    return null;
166
}
167
168
function _CheckISBNChecksum13(isbn) {
169
170
    var sum = 0;
171
    var i,r;
172
173
    if ( isbn.match(/^\d{13}$/) ) {
174
        for (i=0;i<12;i++) {
175
            if ( (i+1) % 2 == 0 ) {
176
                // even
177
                sum += 3 * parseInt(isbn[i],10);
178
            } else {
179
                // odd
180
                sum += parseInt(isbn[i],10);
181
            }
182
        }
183
        r = (10 - (sum % 10)) % 10;
184
        if ( r == isbn[12] ) {
185
            return isbn;
186
        }
187
    }
188
    return null;
189
}
190
191
function IsISBNOk() {
192
193
    var isbn;
194
    var isbn_field;
195
[% IF ( marcflavour == 'MARC21' || marcflavour == 'NORMARC' ) %]
196
    isbn = $('input[id^="tag_020_subfield_a"]').val();
197
    isbn_field = "020";
198
[% ELSIF ( marcflavour == 'UNIMARC' ) %]
199
    isbn = $('input[id^="tag_010_subfield_a"]').val();
200
    isbn_field = "010";
201
[% END %]
202
    var normalized_isbn = _NormalizeISBN(isbn);
203
204
    if ( normalized_isbn.length == 13 ) {
205
        if ( normalized_isbn == _CheckISBNChecksum13(normalized_isbn) ) {
206
            return 0;
207
        }
208
    } else if ( normalized_isbn.length == 10 ) {
209
        if ( normalized_isbn == _CheckISBNChecksum10(normalized_isbn) ) {
210
            return 0;
211
        }
212
    } else if ( normalized_isbn.length == 0 ) {
213
        // no ISBN, no check
214
        return 0;
215
    }
216
    // Invalid ISBN
217
    var StrAlert = "- "+_("The ISBN you entered seems invalid. If you entered it exactly ")+"\n";
218
    StrAlert += _("as it appears on the item, put it in ") + isbn_field + "$z.";
219
    return StrAlert;
220
}
221
138
/**
222
/**
139
 * check if mandatory subfields are written
223
 * check if mandatory subfields are written
140
 */
224
 */
Lines 158-165 function AreMandatoriesNotOk(){ Link Here
158
            [% END %]
242
            [% END %]
159
        [% END %]
243
        [% END %]
160
    [% END %]
244
    [% END %]
161
    var StrAlert = _("Can't save this record because the following field aren't filled:");
245
    var StrAlert = "- "+_("The following fields aren't filled:");
162
    StrAlert += "\n\n";
246
    StrAlert += "\n";
163
    for(var i=0,len=mandatories.length; i<len ; i++){
247
    for(var i=0,len=mandatories.length; i<len ; i++){
164
        var tag=mandatories[i].substr(4,3);
248
        var tag=mandatories[i].substr(4,3);
165
        var subfield=mandatories[i].substr(17,1);
249
        var subfield=mandatories[i].substr(17,1);
Lines 249-259 function AreMandatoriesNotOk(){ Link Here
249
 *
333
 *
250
 */
334
 */
251
function Check(){
335
function Check(){
252
    var StrAlert = AreMandatoriesNotOk();
336
    var StrAlert = _("Can't save this record\n");
253
    if( ! StrAlert ){
337
    var StrMandatoriesNotOk = AreMandatoriesNotOk();
338
[% IF ( RequireValidISBN ) %]
339
    var StrISBNNotOk = IsISBNOk();
340
    if( ! StrMandatoriesNotOk && ! StrISBNNotOk ){
341
[% ELSE %]
342
    if( ! StrMandatoriesNotOk ){
343
[% END %]
254
        document.f.submit();
344
        document.f.submit();
255
        return true;
345
        return true;
256
    } else {
346
    } else {
347
        if ( StrMandatoriesNotOk )
348
            StrAlert += StrMandatoriesNotOk;
349
[% IF ( RequireValidISBN ) %]
350
        if ( StrISBNNotOk )
351
            StrAlert += StrISBNNotOk;
352
[% END %]
257
        alert(StrAlert);
353
        alert(StrAlert);
258
        return false;
354
        return false;
259
    }
355
    }
260
- 

Return to bug 906