Bug 8334 - Authority UNIMARC 100 field plugin
authorVitor FERNANDES <vfernandes@keep.pt>
Wed, 18 Sep 2013 20:58:24 +0000 (17:58 -0300)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 13 Dec 2013 16:31:16 +0000 (16:31 +0000)
This patch adds a plugin for field 100 of UNIMARC
authorities.

To test on a UNIMARC site:
1) Apply the patch
2) Edit some authority framework, field 100
3) Link subfield 'a' to unimarc_field_100_authorities.pl
plugin, save
4) Edit or add auth record, click on '...' to bring plugin
5) Modify field 100a
6) Save record

Thanks to Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> for
converting Vitor's original patch to a Git patch and doing
some tidying.

Signed-off-by: Mathieu Saby <mathieu.saby@univ-rennes2.fr>
Signed-off-by: Stephane Delaye <stephane.delaye@biblibre.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
cataloguing/value_builder/unimarc_field_100_authorities.pl [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_100_authorities.tt [new file with mode: 0644]

diff --git a/cataloguing/value_builder/unimarc_field_100_authorities.pl b/cataloguing/value_builder/unimarc_field_100_authorities.pl
new file mode 100644 (file)
index 0000000..45a8df6
--- /dev/null
@@ -0,0 +1,127 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Copyright (C) 2013 Vitor Fernandes
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+use C4::Auth;
+use CGI;
+use C4::Context;
+use C4::Output;
+
+
+=head1 FUNCTIONS
+
+=head2 plugin_parameters
+
+Other parameters added when the plugin is called by the dopop function
+
+=cut
+
+sub plugin_parameters {
+    my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
+    return "";
+}
+
+sub plugin_javascript {
+    my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
+    my $res           = "
+        <script type='text/javascript'>
+            function Focus$field_number() {
+                return 1;
+            }
+
+            function Blur$field_number() {
+                return 1;
+            }
+
+            function Clic$field_number(i) {
+                var defaultvalue;
+                try {
+                    defaultvalue = document.getElementById(i).value;
+                } catch(e) {
+                    alert('error when getting '+i);
+                    return;
+                }
+                window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_100_authorities.pl&index=\"+i+\"&result=\"+defaultvalue,\"unimarc_field_100\",'width=1000,height=600,toolbar=false,scrollbars=yes');
+            }
+        </script>
+";
+
+    return ( $field_number, $res );
+}
+
+sub wrapper {
+    my ($char) = @_;
+    return "space" if $char eq " ";
+    return "dblspace" if $char eq "  ";
+    return "pipe" if $char eq "|";
+    return $char;
+}
+
+sub plugin {
+    my ($input) = @_;
+    my $index  = $input->param('index');
+    my $result = $input->param('result');
+
+    my $dbh = C4::Context->dbh;
+
+    my $defaultlanguage = C4::Context->preference("UNIMARCField100Language");
+    $defaultlanguage = "fre" if (!$defaultlanguage || length($defaultlanguage) != 3);
+
+    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+        {
+            template_name => "cataloguing/value_builder/unimarc_field_100_authorities.tmpl",
+            query         => $input,
+            type          => "intranet",
+            authnotrequired => 0,
+            flagsrequired   => { editcatalogue => '*' },
+            debug           => 1,
+        }
+    );
+    $result = "        a".$defaultlanguage."y50      ba0" unless $result;
+    my $f1 = substr( $result, 0, 8 );
+    if ( $f1 eq '        ' ) {
+        my @today = Date::Calc::Today();
+        $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
+    }
+
+    my $f2  = substr( $result, 8,  1 ); $f2  = wrapper( $f2 ) if $f2;
+    my $f3  = substr( $result, 9,  3 );
+    my $f4  = substr( $result, 12, 1 ); $f4  = wrapper( $f4 ) if $f4;
+    my $f5  = substr( $result, 13, 2 ); $f5  = wrapper( $f5 ) if $f5;
+    my $f6  = substr( $result, 15, 2 ); $f6  = wrapper( $f6 ) if $f6;
+    my $f7  = substr( $result, 17, 4 ); $f7  = wrapper( $f7 ) if $f7;
+    my $f8  = substr( $result, 21, 2 ); $f8  = wrapper( $f8 ) if $f8;
+    my $f9  = substr( $result, 23, 1 ); $f9  = wrapper( $f9 ) if $f9;
+
+    $template->param(
+        index     => $index,
+        f1        => $f1,
+        "f2$f2"   => 1,
+        f3        => $f3,
+        "f4$f4"   => 1,
+        "f5$f5"   => 1,
+        "f6$f6"   => 1,
+        f7        => $f7,
+        "f8$f8"   => 1,
+        "f9$f9"   => 1,
+    );
+    output_html_with_http_headers $input, $cookie, $template->output;
+}
+
+1;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_100_authorities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/unimarc_field_100_authorities.tt
new file mode 100644 (file)
index 0000000..553ee49
--- /dev/null
@@ -0,0 +1,412 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<title>UNIMARC field 100 builder</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+<body id="cat_unimarc_field_100" class="cat" style="padding:1em;">
+<h3>UNIMARC field 100 builder</h3>
+<form name="f_pop" action="">
+<table>
+    <tr>
+        <td><label for="f1">Date entered on file</label></td>
+        <td><input type="text" name="f1" id="f1" maxlength="8" size="9" value="[% f1 %]" /></td>
+    </tr>
+    <tr>
+        <td><label for="f2">States of authority heading code</label></td>
+        <td>
+            <select name="f2" id="f2" size="1">
+            [% IF ( f2a ) %]
+                <option value="a" selected="selected">a - established</option>
+            [% ELSE %]
+                <option value="a">a - established</option>
+            [% END %]
+            [% IF ( f2c ) %]
+                <option value="c" selected="selected">c - provisional</option>
+            [% ELSE %]
+                <option value="c">c - provisional</option>
+            [% END %]
+            [% IF ( f2x ) %]
+                <option value="x" selected="selected">x - not applicable</option>
+            [% ELSE %]
+                <option value="x">x - not applicable</option>
+            [% END %]
+            </select>
+        </td>
+    </tr>
+
+    <tr>
+    <td><label for="f3">Language of cataloguing (mandatory)</label></td>
+    <td><input type="text" name="f3" id="f3" maxlength="3" size="4" value="[% f3 %]" /></td>
+    </tr>
+
+    <tr>
+        <td><label for="f4">Transliteration code</label></td>
+        <td>
+            <select name="f4" id="f4" size="1">
+
+            [% IF ( f4a ) %]
+                <option value="a" selected="selected">a- ISO transliteration scheme</option>
+            [% ELSE %]
+                <option value="a">a- ISO transliteration scheme</option>
+            [% END %]
+            [% IF ( f4b ) %]
+                <option value="b" selected="selected">b- other</option>
+            [% ELSE %]
+                <option value="b">b- other</option>
+            [% END %]
+            [% IF ( f4c ) %]
+                <option value="c"
+ selected="selected">c- multiple transliterations: ISO or other schemes</option>
+            [% ELSE %]
+                <option value="c">c- multiple transliterations: ISO or other schemes</option>
+            [% END %]
+            [% IF ( f4y ) %]
+                <option value="y" selected="selected">y- no transliteration scheme used</option>
+            [% ELSE %]
+                <option value="y">y- no transliteration scheme used</option>
+            [% END %]
+            </select>
+        </td>
+    </tr>
+    <tr>
+    <td><label for="f5">Character sets (mandatory) 1</label></td>
+        <td>
+            <select name="f5" id="f5" size="1">
+
+            [% IF ( f501 ) %]
+                <option value="01" selected="selected">01- ISO 646, IRV version (basic Latin set)</option>
+            [% ELSE %]
+                <option value="01">01- ISO 646, IRV version (basic Latin set)</option>
+            [% END %]
+            [% IF ( f502 ) %]
+                <option value="02" selected="selected">02- ISO Registration # 37 (basic Cyrillic set)</option>
+            [% ELSE %]
+                <option value="02">02- ISO Registration # 37 (basic Cyrillic set)</option>
+            [% END %]
+            [% IF ( f503 ) %]
+                <option value="03" selected="selected">03- ISO 5426 (extended Latin set)</option>
+            [% ELSE %]
+                <option value="03">03- ISO 5426 (extended Latin set)</option>
+            [% END %]
+            [% IF ( f504 ) %]
+                <option value="04" selected="selected">04- ISO 5427 (extended Cyrillic set)</option>
+            [% ELSE %]
+                <option value="04">04- ISO 5427 (extended Cyrillic set)</option>
+            [% END %]
+            [% IF ( f505 ) %]
+                <option value="05" selected="selected">05- ISO 5428 (Greek set)</option>
+            [% ELSE %]
+                <option value="05">05- ISO 5428 (Greek set)</option>
+            [% END %]
+
+            [% IF ( f506 ) %]
+                <option value="06" selected="selected">06- ISO 6438 (African coded character set)</option>
+            [% ELSE %]
+                <option value="06">06- ISO 6438 (African coded character set)</option>
+            [% END %]
+
+             [% IF ( f507 ) %]
+                <option value="07" selected="selected">07- ISO 10586 (Georgian set)</option>
+            [% ELSE %]
+                <option value="07">07- ISO 10586 (Georgian set)</option>
+            [% END %]
+
+             [% IF ( f508 ) %]
+                <option value="08" selected="selected">08- ISO 8957 (Hebrew set) Table 1</option>
+            [% ELSE %]
+                <option value="08">08- ISO 8957 (Hebrew set) Table 1</option>
+            [% END %]
+
+             [% IF ( f509 ) %]
+                <option value="09" selected="selected">09- ISO 8957 (Hebrew set) Table 2</option>
+            [% ELSE %]
+                <option value="09">09- ISO 8957 (Hebrew set) Table 2</option>
+            [% END %]
+
+             [% IF ( f511 ) %]
+                <option value="11" selected="selected">11- ISO 5426-2 (Latin characters used in minor European
+languages and obsolete typography)
+</option>
+            [% ELSE %]
+                <option value="11">11- ISO 5426-2 (Latin characters used in minor European
+languages and obsolete typography)
+</option>
+            [% END %]
+
+            [% IF ( f550 ) %]
+                <option value="50" selected="selected">50- ISO 10646 Level 3 (Unicode, UTF-8)
+                </option>
+            [% ELSE %]
+                <option value="50">50- ISO 10646 Level 3 (Unicode, UTF-8)</option>
+            [% END %]
+            </select>
+        </td>
+
+    </tr>
+    <tr>
+    <td><label for="f6">Character sets (mandatory) 2</label></td>
+        <td>
+            <select name="f6" id="f6" size="1">
+
+            [% IF ( f6dblspace ) %]
+                    <option value="  " selected="selected">non required value</option>
+            [% ELSE %]
+                    <option value="  ">non required value</option>
+            [% END %]
+
+            [% IF ( f601 ) %]
+                <option value="01" selected="selected">01- ISO 646, IRV version (basic Latin set)</option>
+            [% ELSE %]
+                <option value="01">01- ISO 646, IRV version (basic Latin set)</option>
+            [% END %]
+            [% IF ( f602 ) %]
+                <option value="02" selected="selected">02- ISO Registration # 37 (basic Cyrillic set)</option>
+            [% ELSE %]
+                <option value="02">02- ISO Registration # 37 (basic Cyrillic set)</option>
+            [% END %]
+            [% IF ( f603 ) %]
+                <option value="03"
+ selected="selected">03- ISO 5426 (extended Latin set)</option>
+            [% ELSE %]
+                <option value="03">03- ISO 5426 (extended Latin set)</option>
+            [% END %]
+            [% IF ( f604 ) %]
+                <option value="04" selected="selected">04- ISO 5427 (extended Cyrillic set)</option>
+            [% ELSE %]
+                <option value="04">04- ISO 5427 (extended Cyrillic set)</option>
+            [% END %]
+            [% IF ( f605 ) %]
+                <option value="05" selected="selected">05- ISO 5428 (Greek set)</option>
+            [% ELSE %]
+                <option value="05">05- ISO 5428 (Greek set)</option>
+            [% END %]
+            [% IF ( f606 ) %]
+                <option value="06" selected="selected">06- ISO 6438 (African coded character set)</option>
+            [% ELSE %]
+                <option value="06">06- ISO 6438 (African coded character set)</option>
+            [% END %]
+
+            [% IF ( f607 ) %]
+                <option value="07" selected="selected">07- ISO 10586 (Georgian set)</option>
+            [% ELSE %]
+                <option value="07">07- ISO 10586 (Georgian set)</option>
+            [% END %]
+
+             [% IF ( f608 ) %]
+                <option value="08" selected="selected">08- ISO 8957 (Hebrew set) Table 1</option>
+            [% ELSE %]
+                <option value="08">08- ISO 8957 (Hebrew set) Table 1</option>
+            [% END %]
+
+             [% IF ( f609 ) %]
+                <option value="09" selected="selected">09- ISO 8957 (Hebrew set) Table 2</option>
+            [% ELSE %]
+                <option value="09">09- ISO 8957 (Hebrew set) Table 2</option>
+            [% END %]
+
+             [% IF ( f611 ) %]
+                <option value="11" selected="selected">11- ISO 5426-2 (Latin characters used in minor European
+languages and obsolete typography)</option>
+            [% ELSE %]
+                <option value="11">11- ISO 5426-2 (Latin characters used in minor European
+languages and obsolete typography)</option>
+            [% END %]
+
+            [% IF ( f650 ) %]
+                <option value="50" selected="selected">50- ISO 10646 Level 3 (Unicode, UTF-8)</option>
+            [% ELSE %]
+                <option value="50">ISO 10646 Level 3 (Unicode, UTF-8)</option>
+            [% END %]
+            </select>
+        </td>
+    </tr>
+
+    <tr>
+        <td><label for="f7">Additional character sets</label></td>
+        <td>
+            <input type="text" name="f7" id="f7" maxlength="4" size="5" value="[% f7 %]" />
+        </td>
+    </tr>
+
+    <tr>
+    <td><label for="f8">Script of title</label></td>
+    <td>
+    <select name="f8" id="f8" size="1">
+            [% IF ( f8dblspace ) %]
+                    <option value="  " selected="selected">Non required value</option>
+            [% ELSE %]
+                    <option value="  ">Non required value</option>
+            [% END %]
+
+            [% IF ( f8ba ) %]
+                <option value="ba" selected="selected">ba- Latin</option>
+            [% ELSE %]
+                <option value="ba">ba- Latin</option>
+            [% END %]
+            [% IF ( f8ca ) %]
+                <option value="ca" selected="selected">ca- Cyrillic</option>
+            [% ELSE %]
+                <option value="ca">ca- Cyrillic</option>
+            [% END %]
+
+            [% IF ( f8da ) %]
+                <option value="da" selected="selected">da- Japanese - script unspecified</option>
+            [% ELSE %]
+                <option value="da">da- Japanese - script unspecified</option>
+            [% END %]
+
+            [% IF ( f8db ) %]
+                <option value="db" selected="selected">db- Japanese -
+                Kanji</option>
+            [% ELSE %]
+                <option value="db">db- Japanese - Kanji</option>
+            [% END %]
+
+            [% IF ( f8dc ) %]
+                <option value="dc" selected="selected">dc- Japanese -
+                Kana</option>
+            [% ELSE %]
+                <option value="dc">dc- Japanese - Kana</option>
+            [% END %]
+            [% IF ( f8ea ) %]
+                <option value="ea" selected="selected">ea- Chinese</option>
+            [% ELSE %]
+                <option value="ea">ea- Chinese</option>
+            [% END %]
+            [% IF ( f8fa ) %]
+                <option value="fa" selected="selected">fa- Arabic</option>
+            [% ELSE %]
+                <option value="fa">fa- Arabic</option>
+            [% END %]
+            [% IF ( f8ga ) %]
+                <option value="ga" selected="selected">ga- Greek</option>
+            [% ELSE %]
+                <option value="ga">ga- Greek</option>
+            [% END %]
+            [% IF ( f8ha ) %]
+                <option value="ha" selected="selected">ha- Hebrew</option>
+            [% ELSE %]
+                <option value="ha">ha- Hebrew</option>
+            [% END %]
+            [% IF ( f8ia ) %]
+                <option value="ia" selected="selected">ia- Thai</option>
+            [% ELSE %]
+                <option value="ia">ia- Thai</option>
+            [% END %]
+            [% IF ( f8ja ) %]
+                <option value="ja" selected="selected">ja- Devanagari</option>
+            [% ELSE %]
+                <option value="ja">ja- Devanagari</option>
+            [% END %]
+            [% IF ( f8ka ) %]
+                <option value="ka" selected="selected">ka- Korean</option>
+            [% ELSE %]
+                <option value="ka">ka- Korean</option>
+            [% END %]
+            [% IF ( f8la ) %]
+                <option value="la" selected="selected">la- Tamil</option>
+            [% ELSE %]
+                <option value="la">la- Tamil</option>
+            [% END %]
+            [% IF ( f8zz ) %]
+                <option value="zz" selected="selected">zz- Other</option>
+            [% ELSE %]
+                <option value="zz">zz- Other</option>
+            [% END %]
+
+            [% IF ( f8ma ) %]
+                <option value="ma" selected="selected">ma- Georgian</option>
+            [% ELSE %]
+                <option value="ma">ma- Georgian</option>
+            [% END %]
+
+            [% IF ( f8mb ) %]
+                <option value="mb" selected="selected">mb- Armenian</option>
+            [% ELSE %]
+                <option value="mb">mb- Armenian</option>
+            [% END %]
+            </select>
+    </td>
+    </tr>
+
+    <tr>
+        <td><label for="f9">Direction of Script Cataloguing</label></td>
+        <td>
+            <select name="f9" id="f9" size="1">
+            [% IF ( f90 ) %]
+                <option value="0" selected="selected">0 - left to right</option>
+            [% ELSE %]
+                <option value="0">0 - left to right</option>
+            [% END %]
+            [% IF ( f91 ) %]
+                <option value="1" selected="selected">1 - right to left</option>
+            [% ELSE %]
+                <option value="1">1 - right to left</option>
+            [% END %]
+            </select>
+        </td>
+    </tr>
+</table>
+<p><input type="button" value="OK"  onclick="report();" /> <a href="#" class="cancel close">Cancel</a> </p>
+</form>
+<script type="text/javascript">
+//<![CDATA[
+//     GetPublicationDate(); // running directly.
+//
+//     /**
+//      *  GetPublicationDate.
+//      *  This function get the publication date if it's writen on 210d
+//      */
+//     function GetPublicationDate() {
+//         var PublicationDate = null;
+//
+//         for (i=0 ; i<NbFields ; i++) {
+//             if (doc.f.tag[i].value == '210' && doc.f.subfield[i].value == 'd') {
+//                 if (doc.f.field_value[i].value != ""){
+//                     PublicationDate = doc.f.field_value[i].value;
+//                     document.getElementById('pubdate1').value = PublicationDate;
+//                 }
+//                 return;
+//             }
+//         }
+//     }
+//
+//     /**
+//      *  SetPublicationDate.
+//      *  This function set the publication date here
+//      */
+//     function SetPublicationDate() {
+//         var PublicationDate = document.getElementById('pubdate1').value;
+//         if (PublicationDate == "    " || !PublicationDate){
+//             return ;
+//         }
+//         for (i=0 ; i<NbFields ; i++) {
+//             if (doc.f.tag[i].value == '210' && doc.f.subfield[i].value == 'd') {
+//                 doc.f.field_value[i].value = PublicationDate;
+//                 break;
+//             }
+//         }
+//     }
+
+    function report() {
+        var doc   = opener.document;
+        var field = doc.getElementById("[% index %]");
+
+        document.f_pop.f1.value=document.f_pop.f1.value+'        ';
+        document.f_pop.f3.value=document.f_pop.f3.value+'   ';
+        document.f_pop.f7.value=document.f_pop.f7.value+'    ';
+
+        document.f_pop.f1.value=document.f_pop.f1.value.substring(0,8);
+        document.f_pop.f3.value=document.f_pop.f3.value.substring(0,3);
+        document.f_pop.f7.value=document.f_pop.f7.value.substring(0,4);
+
+        field.value= document.f_pop.f1.value +
+        document.f_pop.f2.value +document.f_pop.f3.value
+        +document.f_pop.f4.value+document.f_pop.f5.value+document.f_pop.f6.value+document.f_pop.f7.value+document.f_pop.f8.value+document.f_pop.f9.value;
+
+//         SetPublicationDate();
+        self.close();
+        return false;
+    }
+//]]>
+</script>
+[% INCLUDE 'popup-bottom.inc' %]