use C4::Koha; # XXX subfield_is_koha_internal_p
use C4::Branch; # XXX subfield_is_koha_internal_p
use C4::ClassSource;
-
-use Date::Calc qw(Today);
+use C4::Dates;
use MARC::File::XML;
debug => 1,
});
-# find itemtype
my $frameworkcode = &GetFrameworkCode($biblionumber);
+my $today_iso = C4::Dates->today('iso');
+$template->param(today_iso => $today_iso);
+
my $tagslib = &GetMarcStructure(1,$frameworkcode);
my $record = GetMarcBiblio($biblionumber);
my $oldrecord = TransformMarcToKoha($dbh,$record);
if ($op eq "additem") {
#-------------------------------------------------------------------------------
# rebuild
- my @tags = $input->param('tag');
+ my @tags = $input->param('tag');
my @subfields = $input->param('subfield');
- my @values = $input->param('field_value');
+ my @values = $input->param('field_value');
# build indicator hash.
- my @ind_tag = $input->param('ind_tag');
+ my @ind_tag = $input->param('ind_tag');
my @indicator = $input->param('indicator');
my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
- my $record=MARC::Record::new_from_xml($xml, 'UTF-8');
+ my $record = MARC::Record::new_from_xml($xml, 'UTF-8');
# if autoBarcode is set to 'incremental', calculate barcode...
# NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
#-------------------------------------------------------------------------------
# retrieve item if exist => then, it's a modif
$itemrecord = C4::Items::GetMarcItem($biblionumber,$itemnumber);
- $nextop="saveitem";
+ $nextop = "saveitem";
#-------------------------------------------------------------------------------
} elsif ($op eq "delitem") {
#-------------------------------------------------------------------------------
push @errors,"barcode_not_unique";
} else {
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
- $itemnumber="";
+ $itemnumber="";
}
$nextop="additem";
}
foreach my $field (@fields) {
next if ($field->tag()<10);
- my @subf=$field->subfields;
+ my @subf = $field->subfields;
+ (defined @subf) or @subf = ();
my %this_row;
# loop through each subfield
for my $i (0..$#subf) {
next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10
&& ($field->tag() ne $itemtagfield
- && $subf[$i][0] ne $itemtagsubfield));
+ && $subf[$i][0] ne $itemtagsubfield));
$witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10);
if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10) {
$row_data{item_value} = $items_data;
$row_data{itemnumber} = $big_array[$i]->{itemnumber};
#reporting this_row values
- $row_data{'nomod'} = $big_array[$i]{'nomod'};
+ $row_data{'nomod'} = $big_array[$i]{'nomod'};
push(@item_value_loop,\%row_data);
}
foreach my $subfield_code (sort keys(%witness)) {
my $i=0;
my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
+my $onlymine = C4::Context->preference('IndependantBranches') &&
+ C4::Context->userenv &&
+ C4::Context->userenv->{flags}!=1 &&
+ C4::Context->userenv->{branch};
+my $branches = GetBranches($onlymine); # build once ahead of time, instead of multiple times later.
+
foreach my $tag (sort keys %{$tagslib}) {
- my $previous_tag = '';
# loop through each subfield
foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
next if subfield_is_koha_internal_p($subfield);
- next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
+ next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
my %subfield_data;
- my $index_subfield= int(rand(1000000));
- if($subfield eq '@'){
+ my $index_subfield = int(rand(1000000));
+ if ($subfield eq '@'){
$subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
} else {
- $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
+ $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
}
- $subfield_data{tag}=$tag;
- $subfield_data{subfield}=$subfield;
- $subfield_data{random}=int(rand(1000000));
-# $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
- $subfield_data{marc_lib} ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
- $subfield_data{mandatory} =$tagslib->{$tag}->{$subfield}->{mandatory};
- $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
+ $subfield_data{tag} = $tag;
+ $subfield_data{subfield} = $subfield;
+ $subfield_data{random} = int(rand(1000000)); # why do we need 2 different randoms?
+# $subfield_data{marc_lib} = $tagslib->{$tag}->{$subfield}->{lib};
+ $subfield_data{marc_lib} ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
+ $subfield_data{mandatory} = $tagslib->{$tag}->{$subfield}->{mandatory};
+ $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
my ($x,$value);
($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord);
$value =~ s/"/"/g;
unless ($value) {
$value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
-
# get today date & replace YYYY, MM, DD if provided in the default value
- my ( $year, $month, $day ) = Today();
- $month = sprintf( "%02d", $month );
- $day = sprintf( "%02d", $day );
+ my ( $year, $month, $day ) = split ',', $today_iso;
$value =~ s/YYYY/$year/g;
$value =~ s/MM/$month/g;
$value =~ s/DD/$day/g;
# (C4::Context->userenv->{flags} != 1) && ($value) && ($value ne C4::Context->userenv->{branch}) ;
# $test and print $input->redirect(".pl?biblionumber=$biblionumber") and exit;
# search for itemcallnumber if applicable
- if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && C4::Context->preference('itemcallnumber')) {
- my $CNtag = substr(C4::Context->preference('itemcallnumber'),0,3);
- my $CNsubfield = substr(C4::Context->preference('itemcallnumber'),3,1);
- my $CNsubfield2 = substr(C4::Context->preference('itemcallnumber'),4,1);
+ my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
+ if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
+ my $CNtag = substr($pref_itemcallnumber, 0, 3);
+ my $CNsubfield = substr($pref_itemcallnumber, 3, 1);
+ my $CNsubfield2 = substr($pref_itemcallnumber, 4, 1);
my $temp2 = $temp->field($CNtag);
if ($temp2) {
$value = ($temp2->subfield($CNsubfield)).' '.($temp2->subfield($CNsubfield2));
#remove any trailing space incase one subfield is used
- $value=~s/^\s+|\s+$//g;
+ $value =~ s/^\s+|\s+$//g;
}
}
+
+ my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" );
+ my $attributes = qq($attributes_no_value value="$value" );
if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
my @authorised_values;
my %authorised_lib;
- my $dbh=C4::Context->dbh;
-
# builds list, depending on authorised value...
- #---- branch
- if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
- #Use GetBranches($onlymine)
- my $onlymine=C4::Context->preference('IndependantBranches') &&
- C4::Context->userenv &&
- C4::Context->userenv->{flags}!=1 &&
- C4::Context->userenv->{branch};
- my $branches = GetBranches($onlymine);
- my @branchloop;
+ if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
foreach my $thisbranch ( sort keys %$branches ) {
push @authorised_values, $thisbranch;
$authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
}
-
- #----- itemtypes
}
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
- my $sth =
- $dbh->prepare(
- "select itemtype,description from itemtypes order by description");
+ push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+ my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
$sth->execute;
- push @authorised_values, ""
- unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
-
+ my $itemtype; # FIXME: double declaration of $itemtype
while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
push @authorised_values, $itemtype;
$authorised_lib{$itemtype} = $description;
}
-
- unless ( $value ) {
- my $default_itemtype;
- my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
- $itype_sth->execute( $biblionumber );
- ( $default_itemtype ) = $itype_sth->fetchrow_array;
- $value = $default_itemtype;
- }
-
- #---- class_sources
+ $value = $itemtype unless ($value);
}
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
- push @authorised_values, ""
- unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+ push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
my $class_sources = GetClassSources();
-
my $default_source = C4::Context->preference("DefaultClassificationSource");
foreach my $class_source (sort keys %$class_sources) {
next unless $class_sources->{$class_source}->{'used'} or
- ($value and $class_source eq $value) or
+ ($value and $class_source eq $value) or
($class_source eq $default_source);
push @authorised_values, $class_source;
$authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
#---- "true" authorised value
}
else {
- $authorised_values_sth->execute(
- $tagslib->{$tag}->{$subfield}->{authorised_value} );
-
- push @authorised_values, ""
- unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
-
+ push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+ $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
push @authorised_values, $value;
$authorised_lib{$value} = $lib;
# it's a thesaurus / authority field
}
elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
- $subfield_data{marc_value} =
- "<input type=\"text\"
- id=\"".$subfield_data{id}."\"
- name=\"field_value\"
- value=\"$value\"
- class=\"input_marceditor\"
- tabindex=\"1\"
- size=\"67\"
- maxlength=\"255\"
- \/>
- <a href=\"#\" class=\"buttonDot\"
- onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
+ $subfield_data{marc_value} = "<input type=\"text\" $attributes />
+ <a href=\"#\" class=\"buttonDot\"
+ onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
";
# it's a plugin field
}
- elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
-
+ elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
# opening plugin
- my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
+ my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
if (do $plugin) {
my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
-
- $subfield_data{marc_value} =
- "<input tabindex=\"1\"
- type=\"text\"
- id=\"".$subfield_data{id}."\"
- name=\"field_value\"
- value=\"$value\"
- class=\"input_marceditor\"
- onfocus=\"Focus$function_name(".$subfield_data{random}.")\"
- size=\"67\"
- maxlength=\"255\"
- onblur=\"Blur$function_name(".$subfield_data{random}."); \" \/>
- <a href=\"#\" class=\"buttonDot\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
- $javascript";
+ $subfield_data{marc_value} = qq[<input $attributes
+ onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
+ onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
+ <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
+ $javascript];
} else {
warn "Plugin Failed: $plugin";
- # supply default input form
- $subfield_data{marc_value} =
- "<input type=\"text\"
- id=\"".$subfield_data{id}."\"
- name=\"field_value\"
- value=\"$value\"
- tabindex=\"1\"
- size=\"67\"
- maxlength=\"255\"
- class=\"input_marceditor\"
- \/>
- ";
+ $subfield_data{marc_value} = "<input $attributes />"; # supply default input form
}
- # it's an hidden field
- }
- elsif ( $tag eq '' ) {
- $subfield_data{marc_value} =
- "<input tabindex=\"1\"
- type=\"hidden\"
- id=\"".$subfield_data{id}."\"
- name=\"field_value\"
- size=\"67\"
- maxlength=\"255\"
- value=\"$value\" \/>
- ";
}
- elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
- $subfield_data{marc_value} =
- "<input type=\"text\"
- id=\"".$subfield_data{id}."\"
- name=\"field_value\"
- class=\"input_marceditor\"
- tabindex=\"1\"
- size=\"67\"
- maxlength=\"255\"
- value=\"$value\"
- \/>";
-
- # it's a standard field
+ elsif ( $tag eq '' ) { # it's an hidden field
+ $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
}
- else {
- if (
- length($value) > 100
- or
- ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
- and $tag < 400 && $subfield eq 'a' )
- or ( $tag >= 500
- and $tag < 600
- && C4::Context->preference("marcflavour") eq "MARC21" )
- )
- {
- $subfield_data{marc_value} =
- "<textarea cols=\"70\"
- rows=\"4\"
- id=\"".$subfield_data{id}."\"
- name=\"field_value\"
- class=\"input_marceditor\"
- tabindex=\"1\"
- size=\"67\"
- maxlength=\"255\"
- >$value</textarea>
- ";
- }
- else {
- $subfield_data{marc_value} =
- "<input type=\"text\"
- id=\"".$subfield_data{id}."\"
- name=\"field_value\"
- value=\"$value\"
- tabindex=\"1\"
- size=\"67\"
- maxlength=\"255\"
- class=\"input_marceditor\"
- \/>
- ";
- }
+ elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ?
+ $subfield_data{marc_value} = qq(<input type="text" $attributes />);
}
-# $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
- push(@loop_data, \%subfield_data);
- $i++
+ elsif ( length($value) > 100
+ or (C4::Context->preference("marcflavour") eq "UNIMARC" and
+ 300 <= $tag && $tag < 400 && $subfield eq 'a' )
+ or (C4::Context->preference("marcflavour") eq "MARC21" and
+ 500 <= $tag && $tag < 600 )
+ ) {
+ # oversize field (textarea)
+ $subfield_data{marc_value} = "<textarea $attributes_no_value>$value</textarea>\n";
+ } else {
+ # it's a standard field
+ $subfield_data{marc_value} = "<input $attributes />";
}
+# $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
+ push (@loop_data, \%subfield_data);
+ $i++
+ }
}
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
$template->param( title => $record->title() ) if ($record ne "-1");
-$template->param(item_loop => \@item_value_loop,
- item_header_loop => \@header_value_loop,
- biblionumber => $biblionumber,
- title => $oldrecord->{title},
- author => $oldrecord->{author},
- item => \@loop_data,
- itemnumber => $itemnumber,
- itemtagfield => $itemtagfield,
- itemtagsubfield =>$itemtagsubfield,
- op => $nextop,
- opisadd => ($nextop eq "saveitem")?0:1);
+$template->param(
+ biblionumber => $biblionumber,
+ title => $oldrecord->{title},
+ author => $oldrecord->{author},
+ item_loop => \@item_value_loop,
+ item_header_loop => \@header_value_loop,
+ item => \@loop_data,
+ itemnumber => $itemnumber,
+ itemtagfield => $itemtagfield,
+ itemtagsubfield => $itemtagsubfield,
+ op => $nextop,
+ opisadd => ($nextop eq "saveitem") ? 0 : 1,
+);
foreach my $error (@errors) {
$template->param($error => 1);
}
use C4::Context;
-
+require C4::Dates;
my $DEBUG = 0;
=head1
=cut
sub plugin_parameters {
-my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
-return "";
+# my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
+ return "";
}
=head1
my $function_name= "barcode".(int(rand(100000))+1);
# find today's date
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
- localtime(time);
- $year +=1900;
- $mon +=1;
- if (length($mon)==1) {
- $mon = "0".$mon;
- }
- if (length($mday)==1) {
- $mday = "0".$mday;
- }
- if (length($hour)==1) {
- $hour = "0".$hour;
- }
- if (length($min)==1) {
- $min = "0".$min;
- }
- if (length($sec)==1) {
- $hour = "0".$sec;
- }
-
- my $date = "$year";
-
- my ($tag,$subfield) = GetMarcFromKohaField("items.barcode","");
- my ($loctag,$locsubfield) = GetMarcFromKohaField("items.homebranch","");
+ my ($year, $mon, $day) = split('-', C4::Dates->today('iso'));
+ my ($tag,$subfield) = GetMarcFromKohaField("items.barcode", '');
+ my ($loctag,$locsubfield) = GetMarcFromKohaField("items.homebranch", '');
my $nextnum;
my $query;
- my $scr;
+ my $scr;
my $autoBarcodeType = C4::Context->preference("autoBarcode");
- warn "Barcode type = $autoBarcodeType" if $DEBUG;
- unless ($autoBarcodeType eq 'OFF' or !$autoBarcodeType) {
-
+ warn "Barcode type = $autoBarcodeType" if $DEBUG;
+ if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
+ # don't return a value unless we have the appropriate syspref set
+ return ($function_name,
+ "<script type=\"text/javascript\">
+ // autoBarcodeType OFF (or not defined)
+ function Focus$function_name() { return 0;}
+ function Clic$function_name() { return 0;}
+ function Blur$function_name() { return 0;}
+ </script>");
+ }
if ($autoBarcodeType eq 'annual') {
$query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
my $sth=$dbh->prepare($query);
$sth->execute("$year%");
while (my ($count)= $sth->fetchrow_array) {
- warn "Examining Record: $count" if $DEBUG;
+ warn "Examining Record: $count" if $DEBUG;
$nextnum = $count if $count;
}
$nextnum++;
$nextnum = sprintf("%0*d", "4",$nextnum);
$nextnum = "$year-$nextnum";
- $scr = "
- for (i=0 ; i<document.f.field_value.length ; i++) {
- if (document.f.tag[i].value == '$tag' && document.f.subfield[i].value == '$subfield') {
- if (document.f.field_value[i].value == '') {
- document.f.field_value[i].value = '$nextnum';
- }
- }
- }";
}
elsif ($autoBarcodeType eq 'incremental') {
# not the best, two catalogers could add the same barcode easily this way :/
$query = "select max(abs(barcode)) from items";
- my $sth=$dbh->prepare($query);
+ my $sth = $dbh->prepare($query);
$sth->execute();
while (my ($count)= $sth->fetchrow_array) {
$nextnum = $count;
}
$nextnum++;
- $scr = "
- for (i=0 ; i<document.f.field_value.length ; i++) {
- if (document.f.tag[i].value == '$tag' && document.f.subfield[i].value == '$subfield') {
- if (document.f.field_value[i].value == '') {
- document.f.field_value[i].value = '$nextnum';
- }
- }
- }";
- }
- elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit
- $year = substr($year, -2);
- $query = "SELECT MAX(CAST(SUBSTRING(barcode,7,4) AS signed)) FROM items WHERE barcode REGEXP ?";
- my $sth=$dbh->prepare($query);
- $sth->execute("^[a-zA-Z]{1,}$year");
- while (my ($count)= $sth->fetchrow_array) {
- $nextnum = $count if $count;
- warn "Existing incremental number = $nextnum" if $DEBUG;
- }
- $nextnum++;
- $nextnum = sprintf("%0*d", "4",$nextnum);
- $nextnum = $year . $mon . $nextnum;
- warn "New Barcode = $nextnum" if $DEBUG;
- $scr = "
- for (i=0 ; i<document.f.field_value.length ; i++) {
- if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') {
- fnum = i;
- }
- }
- for (i=0 ; i<document.f.field_value.length ; i++) {
- if (document.f.tag[i].value == '$tag' && document.f.subfield[i].value == '$subfield') {
- if (document.f.field_value[i].value == '') {
- document.f.field_value[i].value = document.f.field_value[fnum].value + '$nextnum';
- }
- }
- }";
+ }
+ elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit
+ $year = substr($year, -2);
+ $query = "SELECT MAX(CAST(SUBSTRING(barcode,7,4) AS signed)) FROM items WHERE barcode REGEXP ?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute("^[a-zA-Z]{1,}$year");
+ while (my ($count)= $sth->fetchrow_array) {
+ $nextnum = $count if $count;
+ warn "Existing incremental number = $nextnum" if $DEBUG;
+ }
+ $nextnum++;
+ $nextnum = sprintf("%0*d", "4",$nextnum);
+ $nextnum = $year . $mon . $nextnum;
+ warn "New hbyymmincr Barcode = $nextnum" if $DEBUG;
+ $scr = "
+ for (i=0 ; i<document.f.field_value.length ; i++) {
+ if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') {
+ fnum = i;
+ }
+ }
+ if (\$('#' + id).val() == '' || force) {
+ \$('#' + id).val(document.f.field_value[fnum].value + '$nextnum');
}
+ ";
+ }
+ # default js body (if not filled by hbyymmincr)
+ $scr or $scr = <<END_OF_JS;
+if (\$('#' + id).val() == '' || force) {
+ \$('#' + id).val('$nextnum');
+}
+END_OF_JS
- my $res = "
-<script type=\"text/javascript\">
+ my $js = <<END_OF_JS;
+<script type="text/javascript">
//<![CDATA[
-//function Blur$function_name(index) {
-//need this?
-//}
-
-function Focus$function_name(subfield_managed) {";
-
-$res .= $scr;
-$res .= "
-return 0;
+function Blur$function_name(index) {
+ //barcode validation might go here
}
-function Clic$function_name(subfield_managed) {";
+function Focus$function_name(subfield_managed, id, force) {
+$scr
+ return 0;
+}
-$res .= $scr;
-$res .= "
-return 0;
+function Clic$function_name(id) {
+ return Focus$function_name('not_relavent', id, 1);
}
//]]>
</script>
-";
- # don't return a value unless we have the appropriate syspref set
- return ($function_name,$res);
- }
- else {
- return ($function_name,"<script type=\"text/javascript\">function Focus$function_name() { return 0;}</script>");
- }
+END_OF_JS
+ return ($function_name, $js);
}
=head1
-plugin : the true value_builded. The screen that is open in the popup window.
+plugin: useless here
=cut
sub plugin {
-my ($input) = @_;
-return "";
+ # my ($input) = @_;
+ return "";
}
1;
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
-
-
=head1
-plugin_parameters : other parameters added when the plugin is called by the dopop function
+plugin_parameters : useless here
=cut
sub plugin_parameters {
- my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
+ # my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
return "";
}
plugin_javascript : the javascript function called when the user enters the subfield.
contain 3 javascript functions :
-* one called when the field is entered (OnFocus). Named FocusXXX
-* one called when the field is leaved (onBlur). Named BlurXXX
-* one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX
+* one called when the field is entered (OnFocus) named FocusXXX
+* one called when the field is left (onBlur ) named BlurXXX
+* one called when the ... link is clicked (onClick) named ClicXXX
returns :
* XXX
=cut
sub plugin_javascript {
- my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
- my $function_name= "dateaccessioned".(int(rand(100000))+1);
+ # my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
+ my $function_name = "dateaccessioned".(int(rand(100000))+1);
- # find today's date
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
- localtime(time);
- $year +=1900;
- $mon +=1;
- $pmon = sprintf("%0*d", "2",$mon);
-
- $pmday = sprintf("%0*d", "2",$mday);
- my $date = "$year-$pmon-$pmday";
+ require C4::Dates;
+ my $date = C4::Dates->today('iso');
# find the tag/subfield mapped to items.dateaccessioned
my ($tag,$subfield) = GetMarcFromKohaField("items.dateaccessioned","");
- my $res = "
-<script type=\"text/javascript\">
+ my $res = <<END_OF_JS;
+<script type="text/javascript">
//<![CDATA[
+//
+// from: cataloguing/value_builder/dateaccessioned.pl
+
function Blur$function_name(index) {
-//need this?
+ //date validation could go here
}
-function Focus$function_name(subfield_managed) {
- for (i=0 ; i<document.f.field_value.length ; i++) {
- if (document.f.tag[i].value == '$tag' && document.f.subfield[i].value == '$subfield') {
- if (document.f.field_value[i].value == '') {
- document.f.field_value[i].value = '$date';
- }
- }
- }
-return 0;
+function Focus$function_name(subfield_managed, id, force) {
+ //var summary = "";
+ //for (i=0 ; i<document.f.field_value.length ; i++) {
+ // summary += i + ": " + document.f.tag[i].value + " " + document.f.subfield[i].value + ": " + document.f.field_value[i].value + "\\n";
+ //}
+ //alert("Got focus, subfieldmanaged: " + subfield_managed + "\\n" + summary);
+ set_to_today(id); // defined in additem.pl HEAD
+ return 0;
}
-function Clic$function_name(subfield_managed) {
+function Clic$function_name(id) {
+ set_to_today(id, 1); // defined in additem.pl HEAD
+ return 0;
}
//]]>
</script>
-";
- return ($function_name,$res);
+END_OF_JS
+ return ($function_name, $res);
}
=head1
-plugin : the true value_builded. The screen that is open in the popup window.
+plugin: useless here.
=cut
sub plugin {
-my ($input) = @_;
-return "";
+# my ($input) = @_;
+ return "";
}
1;