From 99737d565b938fe26db60960daaddb25826bbcd4 Mon Sep 17 00:00:00 2001
From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Date: Fri, 18 Dec 2015 11:40:02 -0300
Subject: [PATCH] Bug 8643: Add important constraint to marc subfields
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fix permits to add an "Important" option to the marc structure pages.

Testing:

1) Apply the patch
2) Run updatedatabase.pl
3) Regenerate CSS
4) Define 100 as an "important" field ( Administration » MARC bibliographic framework » MARC structure ( Default Frameword) » Edit )
5) Define 100$a as an "important" subfield (Administration » MARC bibliographic framework » MARC structure (Default Frameword) » Subfield » Onglet a)
6) Edit a record to clear the field 100 (subfields are all blank)
7) Save the record.
8) Validate the following message:

A few important fields are not filled:

    * tag 100 subfield a Nom de personne in tab
    * Field 100 is important, at least one of its subfields should be filled.

Are you sure you want to save?

Sponsored by the CCSR ( http://www.ccsr.qc.ca )
---
 C4/Biblio.pm                                       |  12 +-
 admin/marc_subfields_structure.pl                  |  12 +-
 admin/marctagstructure.pl                          |  16 ++-
 cataloguing/addbiblio.pl                           |   9 +-
 cataloguing/additem.pl                             |   1 +
 .../bug-8643-add_important_constraint.perl         |  11 ++
 installer/data/mysql/kohastructure.sql             |   2 +
 koha-tmpl/intranet-tmpl/prog/css/addbiblio.css     |   4 +
 .../intranet-tmpl/prog/css/src/staff-global.scss   |   4 +
 .../en/modules/admin/marc_subfields_structure.tt   |   9 ++
 .../prog/en/modules/admin/marctagstructure.tt      |  10 ++
 .../prog/en/modules/cataloguing/addbiblio.tt       | 129 ++++++++++++++++++++-
 .../prog/en/modules/cataloguing/additem.tt         |  34 ++++--
 koha-tmpl/intranet-tmpl/prog/js/cataloging.js      |  12 ++
 14 files changed, 241 insertions(+), 24 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index c12b108..de4af99 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -893,25 +893,26 @@ sub GetMarcStructure {
 
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare(
-        "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable,ind1_defaultvalue,ind2_defaultvalue
+        "SELECT tagfield,liblibrarian,libopac,mandatory,repeatable,important,ind1_defaultvalue,ind2_defaultvalue
         FROM marc_tag_structure 
         WHERE frameworkcode=? 
         ORDER BY tagfield"
     );
     $sth->execute($frameworkcode);
-    my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable, $ind1_defaultvalue, $ind2_defaultvalue );
+    my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable, $important, $ind1_defaultvalue, $ind2_defaultvalue );
 
-    while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable, $ind1_defaultvalue, $ind2_defaultvalue ) = $sth->fetchrow ) {
+    while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable, $important, $ind1_defaultvalue, $ind2_defaultvalue ) = $sth->fetchrow ) {
         $res->{$tag}->{lib}        = ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
         $res->{$tag}->{tab}        = "";
         $res->{$tag}->{mandatory}  = $mandatory;
+        $res->{$tag}->{important}  = $important;
         $res->{$tag}->{repeatable} = $repeatable;
     $res->{$tag}->{ind1_defaultvalue} = $ind1_defaultvalue;
     $res->{$tag}->{ind2_defaultvalue} = $ind2_defaultvalue;
     }
 
     $sth = $dbh->prepare(
-        "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue,maxlength
+        "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab,mandatory,repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link,defaultvalue,maxlength,important
          FROM   marc_subfield_structure 
          WHERE  frameworkcode=? 
          ORDER BY tagfield,tagsubfield
@@ -935,13 +936,14 @@ sub GetMarcStructure {
     while (
         (   $tag,          $subfield,      $liblibrarian, $libopac, $tab,    $mandatory, $repeatable, $authorised_value,
             $authtypecode, $value_builder, $kohafield,    $seealso, $hidden, $isurl,     $link,       $defaultvalue,
-            $maxlength
+            $maxlength, $important
         )
         = $sth->fetchrow
       ) {
         $res->{$tag}->{$subfield}->{lib}              = ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
         $res->{$tag}->{$subfield}->{tab}              = $tab;
         $res->{$tag}->{$subfield}->{mandatory}        = $mandatory;
+        $res->{$tag}->{$subfield}->{important}        = $important;
         $res->{$tag}->{$subfield}->{repeatable}       = $repeatable;
         $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
         $res->{$tag}->{$subfield}->{authtypecode}     = $authtypecode;
diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl
index 2519649..594233b 100755
--- a/admin/marc_subfields_structure.pl
+++ b/admin/marc_subfields_structure.pl
@@ -191,6 +191,7 @@ if ( $op eq 'add_form' ) {
         $row_data{isurl}             = $data->{isurl};
         $row_data{row}               = $i;
         $row_data{link}              = $data->{'link'};
+        $row_data{important}         = $data->{important};
         push( @loop_data, \%row_data );
         $i++;
     }
@@ -215,6 +216,7 @@ if ( $op eq 'add_form' ) {
     $row_data{authtypes}         = \@authtypes;
     $row_data{link}              = "";
     $row_data{row}               = $i;
+    $row_data{important}         = "";
     push( @loop_data, \%row_data );
 
     $template->param( 'use_heading_flags_p'      => 1 );
@@ -238,11 +240,11 @@ elsif ( $op eq 'add_validate' ) {
 #                                     values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
 #     );
     my $sth_insert = $dbh->prepare(qq{
-        insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue,maxlength)
-        values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+        insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,important,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue,maxlength)
+        values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
     });
     my $sth_update = $dbh->prepare(qq{
-        update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?,  link=?, defaultvalue=?, maxlength=?
+        update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, important=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?,  link=?, defaultvalue=?, maxlength=?
         where tagfield=? and tagsubfield=? and frameworkcode=?
     });
     my @tagsubfield       = $input->multi_param('tagsubfield');
@@ -267,6 +269,7 @@ elsif ( $op eq 'add_validate' ) {
         my $libopac          = $libopac[$i];
         my $repeatable       = $input->param("repeatable$i") ? 1 : 0;
         my $mandatory        = $input->param("mandatory$i") ? 1 : 0;
+        my $important        = $input->param("important$i") ? 1 : 0;
         my $kohafield        = $kohafield[$i];
         my $tab              = $tab[$i];
         my $seealso          = $seealso[$i];
@@ -288,6 +291,7 @@ elsif ( $op eq 'add_validate' ) {
                     $libopac,
                     $repeatable,
                     $mandatory,
+                    $important,
                     $kohafield,
                     $tab,
                     $seealso,
@@ -319,6 +323,7 @@ elsif ( $op eq 'add_validate' ) {
                     $libopac,
                     $repeatable,
                     $mandatory,
+                    $important,
                     $kohafield,
                     $tab,
                     $seealso,
@@ -401,6 +406,7 @@ else {    # DEFAULT
         $row_data{kohafield}        = $results->[$i]{'kohafield'};
         $row_data{repeatable}       = $results->[$i]{'repeatable'};
         $row_data{mandatory}        = $results->[$i]{'mandatory'};
+        $row_data{important}        = $results->[$i]{'important'};
         $row_data{tab}              = $results->[$i]{'tab'};
         $row_data{seealso}          = $results->[$i]{'seealso'};
         $row_data{authorised_value} = $results->[$i]{'authorised_value'};
diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl
index e34edd5..d7d7447 100755
--- a/admin/marctagstructure.pl
+++ b/admin/marctagstructure.pl
@@ -89,7 +89,7 @@ if ($op eq 'add_form') {
 	#---- if primkey exists, it's a modify action, so read values to modify...
 	my $data;
 	if ($searchfield) {
-        $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,ind1_defaultvalue,ind2_defaultvalue from marc_tag_structure where tagfield=? and frameworkcode=?");
+        $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,important,ind1_defaultvalue,ind2_defaultvalue from marc_tag_structure where tagfield=? and frameworkcode=?");
 		$sth->execute($searchfield,$frameworkcode);
 		$data=$sth->fetchrow_hashref;
 	}
@@ -108,6 +108,7 @@ if ($op eq 'add_form') {
             repeatable => $data->{'repeatable'},
             mandatory => $data->{'mandatory'},
             authorised_value => $data->{authorised_value},
+            important => $data->{'important'},
             ind1_defaultvalue => $data->{'ind1_defaultvalue'},
             ind2_defaultvalue => $data->{'ind2_defaultvalue'}
     );  # FIXME: move checkboxes to presentation layer
@@ -120,17 +121,19 @@ if ($op eq 'add_form') {
 	my $libopac          = $input->param('libopac');
 	my $repeatable       = $input->param('repeatable') ? 1 : 0;
 	my $mandatory        = $input->param('mandatory')  ? 1 : 0;
+        my $important        = $input->param('important')  ? 1 : 0;
 	my $authorised_value = $input->param('authorised_value');
     my $ind1_defaultvalue = $input->param('ind1_defaultvalue');
     my $ind2_defaultvalue = $input->param('ind2_defaultvalue');
     if ($input->param('modif')) {
         $sth = $dbh->prepare(
-        "UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,authorised_value=?, ind1_defaultvalue=?, ind2_defaultvalue=? WHERE frameworkcode=? AND tagfield=?"
+        "UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,important=? ,authorised_value=?, ind1_defaultvalue=?, ind2_defaultvalue=? WHERE frameworkcode=? AND tagfield=?"
         );
         $sth->execute(  $liblibrarian,
                         $libopac,
                         $repeatable,
                         $mandatory,
+                        $important,
                         $authorised_value,
                         $ind1_defaultvalue,
                         $ind2_defaultvalue,
@@ -139,13 +142,14 @@ if ($op eq 'add_form') {
         );
     } else {
         $sth = $dbh->prepare(
-        "INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?)"
+        "INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,important,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?,?)"
         );
         $sth->execute($tagfield,
                       $liblibrarian,
                       $libopac,
                       $repeatable,
                       $mandatory,
+                      $important,
                       $authorised_value,
                       $ind1_defaultvalue,
                       $ind2_defaultvalue,
@@ -216,6 +220,7 @@ if ($op eq 'add_form') {
 		              marc_tag_structure.libopac as mts_libopac,
 		              marc_tag_structure.repeatable as mts_repeatable,
 		              marc_tag_structure.mandatory as mts_mandatory,
+                      marc_tag_structure.important as mts_important,
 		              marc_tag_structure.authorised_value as mts_authorized_value,
                   marc_tag_structure.ind1_defaultvalue as mts_ind1_defaultvalue,
                   marc_tag_structure.ind1_defaultvalue as mts_ind2_defaultvalue,
@@ -239,6 +244,7 @@ if ($op eq 'add_form') {
 			$row_data{liblibrarian}     = $results[$i]->{'mts_liblibrarian'};
 			$row_data{repeatable}       = $results[$i]->{'mts_repeatable'};
 			$row_data{mandatory}        = $results[$i]->{'mts_mandatory'};
+            $row_data{important}        = $results[$i]->{'mts_important'};
 			$row_data{authorised_value} = $results[$i]->{'mts_authorised_value'};
             $row_data{ind1_defaultvalue} = $results[$i]->{'mts_ind1_defaultvalue'};
             $row_data{ind2_defaultvalue} = $results[$i]->{'mts_ind2_defaultvalue'};
@@ -251,6 +257,7 @@ if ($op eq 'add_form') {
 				$subfield_data{kohafield}        = $results[$j]->{'kohafield'};
 				$subfield_data{repeatable}       = $results[$j]->{'repeatable'};
 				$subfield_data{mandatory}        = $results[$j]->{'mandatory'};
+                $subfield_data{important}        = $results[$j]->{'important'};
 				$subfield_data{tab}              = $results[$j]->{'tab'};
 				$subfield_data{seealso}          = $results[$j]->{'seealso'};
 				$subfield_data{authorised_value} = $results[$j]->{'authorised_value'};
@@ -283,6 +290,7 @@ if ($op eq 'add_form') {
 			$row_data{liblibrarian}     = $results->[$i]{'liblibrarian'};
 			$row_data{repeatable}       = $results->[$i]{'repeatable'};
 			$row_data{mandatory}        = $results->[$i]{'mandatory'};
+            $row_data{important}        = $results->[$i]{'important'};
 			$row_data{authorised_value} = $results->[$i]{'authorised_value'};
             $row_data{ind1_defaultvalue} = $results->[$i]{'ind1_defaultvalue'};
             $row_data{ind2_defaultvalue} = $results->[$i]{'ind2_defaultvalue'};
@@ -313,7 +321,7 @@ output_html_with_http_headers $input, $cookie, $template->output;
 sub StringSearch  {
 	my ($searchstring,$frameworkcode)=@_;
 	my $sth = C4::Context->dbh->prepare("
-    SELECT tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,ind1_defaultvalue,ind2_defaultvalue
+    SELECT tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,important,ind1_defaultvalue,ind2_defaultvalue
      FROM  marc_tag_structure
      WHERE (tagfield >= ? and frameworkcode=?)
     ORDER BY tagfield
diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index c4ed49d..51e0fa6 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -305,6 +305,7 @@ sub create_input {
         marc_lib       => $tagslib->{$tag}->{$subfield}->{lib},
         tag_mandatory  => $tagslib->{$tag}->{mandatory},
         mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
+        important      => $tagslib->{$tag}->{$subfield}->{important},
         repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
         kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
         index          => $index_tag,
@@ -318,13 +319,15 @@ sub create_input {
         $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
     }
     # Subfield is hidden depending of hidden and mandatory flag, and is always
-    # shown if it contains anything or if its field is mandatory.
+    # shown if it contains anything or if its field is mandatory or important.
     my $tdef = $tagslib->{$tag};
     $subfield_data{visibility} = "display:none;"
         if $tdef->{$subfield}->{hidden} % 2 == 1 &&
            $value eq '' &&
            !$tdef->{$subfield}->{mandatory} &&
-           !$tdef->{mandatory};
+           !$tdef->{mandatory} &&
+           !$tdef->{$subfield}->{important} &&
+           !$tdef->{important};
     # expand all subfields of 773 if there is a host item provided in the input
     $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
 
@@ -604,6 +607,7 @@ sub build_tabs {
                             tag_lib       => $tagslib->{$tag}->{lib},
                             repeatable       => $tagslib->{$tag}->{repeatable},
                             mandatory       => $tagslib->{$tag}->{mandatory},
+                            important       => $tagslib->{$tag}->{important},
                             subfield_loop => \@subfields_data,
                             fixedfield    => $tag < 10?1:0,
                             random        => CreateKey,
@@ -650,6 +654,7 @@ sub build_tabs {
                         tag_lib          => $tagslib->{$tag}->{lib},
                         repeatable       => $tagslib->{$tag}->{repeatable},
                         mandatory       => $tagslib->{$tag}->{mandatory},
+                        important       => $tagslib->{$tag}->{important},
                         indicator1       => ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue} ), #if not set, try to load the default value
                         indicator2       => ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue} ), #use short-circuit operator for efficiency
                         subfield_loop    => \@subfields_data,
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 7b6d5e4..220bf8b 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -130,6 +130,7 @@ sub generate_subfield_form {
         $subfield_data{subfield}   = $subfieldtag;
         $subfield_data{marc_lib}   ="<span id=\"error$i\" title=\"".$subfieldlib->{lib}."\">".$subfieldlib->{lib}."</span>";
         $subfield_data{mandatory}  = $subfieldlib->{mandatory};
+        $subfield_data{important}  = $subfieldlib->{important};
         $subfield_data{repeatable} = $subfieldlib->{repeatable};
         $subfield_data{maxlength}  = $subfieldlib->{maxlength};
         
diff --git a/installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl b/installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl
new file mode 100644
index 0000000..4a972cd
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug-8643-add_important_constraint.perl
@@ -0,0 +1,11 @@
+$DBversion = "XXX";
+if ( CheckVersion($DBversion) ) {
+    if ( !column_exists( 'marc_subfield_structure', 'important') ){
+        $dbh->do("ALTER TABLE marc_subfield_structure ADD COLUMN important TINYINT(4) NOT NULL DEFAULT 0  AFTER mandatory");
+    }
+    if ( !column_exists( 'marc_subfield_structure', 'important') ){
+        $dbh->do("ALTER TABLE marc_tag_structure ADD COLUMN important TINYINT(4) NOT NULL DEFAULT 0  AFTER mandatory");
+    }
+    SetVersion($DBversion);
+    print "Upgrade to $DBversion done (Bug 8643 - Add important constraint to marc subfields)\n";
+}
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 76798c3..aaf6c3d 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1141,6 +1141,7 @@ CREATE TABLE `marc_subfield_structure` (
   `libopac` varchar(255) NOT NULL default '',
   `repeatable` tinyint(4) NOT NULL default 0,
   `mandatory` tinyint(4) NOT NULL default 0,
+  `important` tinyint(4) NOT NULL DEFAULT '0',
   `kohafield` varchar(40) default NULL,
   `tab` tinyint(1) default NULL,
   `authorised_value` varchar(32) default NULL,
@@ -1171,6 +1172,7 @@ CREATE TABLE `marc_tag_structure` (
   `libopac` varchar(255) NOT NULL default '',
   `repeatable` tinyint(4) NOT NULL default 0,
   `mandatory` tinyint(4) NOT NULL default 0,
+  `important` tinyint(4) NOT NULL DEFAULT '0',
   `authorised_value` varchar(10) default NULL,
   `ind1_defaultvalue` varchar(1) NOT NULL default '',
   `ind2_defaultvalue` varchar(1) NOT NULL default '',
diff --git a/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css b/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css
index 5670a23..1fd4540 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css
+++ b/koha-tmpl/intranet-tmpl/prog/css/addbiblio.css
@@ -119,6 +119,10 @@ a.tagnum {
 .mandatory_marker {
 	color: red;
 }
+
+.important_marker {
+    color: black;
+}
 .linktools { display: block; white-space: nowrap; }
 .linktools a { font-size : 75%; display:block;text-decoration:none;}
 .linktools a {margin:0 2px;padding:2px;background-color:#FFF;text-align:center; }
diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
index ee75489..ee29da3 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
@@ -1928,6 +1928,10 @@ dd {
     background-color: #FFFF99;
 }
 
+.important_subfield_not_filled {
+       background-color : #FFFFCC;
+}
+
 .content_hidden {
     display: none;
     visibility: hidden; // you propably don't need to change this one
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt
index f4d0fef..8edb20b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt
@@ -87,6 +87,14 @@
                                 <input type="checkbox" id="mandatory[% loo.row | html %]" name="mandatory[% loo.row | html %]" value="1" />
                             [% END %]
                         </li>
+                        <li>
+                            <label for="important[% loo.row | html %]">Important: </label>
+                            [% IF loo.important %]
+                                <input type="checkbox" id="important[% loo.row | html %]" name="important[% loo.row | html %]" checked="checked" value="1" />
+                            [% ELSE %]
+                                <input type="checkbox" id="important[% loo.row | html %]" name="important[% loo.row | html %]" value="1" />
+                            [% END %]
+                        </li>
                         <li><label for="tab[% loo.row | html %]">Managed in tab: </label>
                             <select name="tab" tabindex="" size="1" id="tab[% loo.row | html %]">
                             [%- IF ( loo.tab ==  -1 ) -%]
@@ -281,6 +289,7 @@
             [% IF ( loo.kohafield ) %] | Koha field: [% loo.kohafield | html %], [% END %]
             [% IF ( loo.repeatable ) %]Repeatable, [% ELSE %]Not repeatable,[% END %]
             [% IF ( loo.mandatory ) %]Mandatory, [% ELSE %]Not mandatory,[% END %]
+            [% IF ( loo.important ) %]Important, [% ELSE %]Not important,[% END %]
             [% IF ( loo.seealso ) %] | See Also: [% loo.seealso | html %],[% END %]
             [% IF ( loo.hidden ) %]hidden,[% END %]
             [% IF ( loo.isurl ) %]is a URL,[% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt
index 331a957..44f0de3 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marctagstructure.tt
@@ -80,12 +80,20 @@
             <input type="checkbox" name="mandatory" id="mandatory" value="1" />
         [% END %]
     </li>
+    <li><label for="important">Important: </label>
+        [% IF ( important ) %]
+            <input type="checkbox" name="important" id="important" value="1" checked="checked" />
+        [% ELSE %]
+            <input type="checkbox" name="important" id="important" value="1" />
+        [% END %]
+    </li>
     <li><label for="ind1_defaultvalue">First indicator default value: </label>
         <input id="ind1_defaultvalue" type="text" name="ind1_defaultvalue" value="[% ind1_defaultvalue | html %]" maxlength="1" size="1" />
     </li>
     <li><label for="ind2_defaultvalue">Second indicator default value: </label>
         <input id="ind2_defaultvalue" type="text" name="ind2_defaultvalue" value="[% ind2_defaultvalue | html %]" maxlength="1" size="1" />
     </li>
+        (if you select a value here, the indicators will be limited to the authorized value list)</li>
     <li><label for="authorised_value">Authorized value: </label>
         <select name="authorised_value" id="authorised_value" size="1">
             <option value=""></option>
@@ -176,6 +184,7 @@
         <th>Lib</th>
         <th>Repeatable</th>
         <th>Mandatory</th>
+        <th>Important</th>
         <th>Auth value</th>
         <th>Indicator 1</th>
         <th>Indicator 2</th>
@@ -199,6 +208,7 @@
             </td>
             <td>[% IF ( loo.repeatable ) %]Yes[% ELSE %]No[% END %]</td>
             <td>[% IF ( loo.mandatory ) %]Yes[% ELSE %]No[% END %]</td>
+            <td>[% IF ( loo.important ) %]Yes[% ELSE %]No[% END %]</td>
             <td>[% loo.authorised_value | html %]</td>
             <td>[% loo.ind1_defaultvalue | html %]</td>
             <td>[% loo.ind2_defaultvalue | html %]</td>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
index de2429b..2cf8b9a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt
@@ -253,7 +253,7 @@ function AreMandatoriesNotOk(){
     var flag=0;
     var tabflag= new Array();  
     [% FOREACH BIG_LOO IN BIG_LOOP %]
-    	[% FOREACH innerloo IN BIG_LOO.innerloop %]
+        [% FOREACH innerloo IN BIG_LOO.innerloop %]
 	        [% IF ( innerloo.mandatory ) %]
     	    	mandatoriesfields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]"));
         	[% END %]
@@ -339,7 +339,7 @@ function AreMandatoriesNotOk(){
     	
     	if(isempty){
     		flag = 1;
-                StrAlert += "\t* " + _("Field %s is mandatory, at least one of its subfields must be filled.").format(arr[0]) + "\n";
+            StrAlert += "\t* " + _("Field %s is mandatory, at least one of its subfields must be filled.").format(arr[0]) + "\n";
     	}
     	
     }
@@ -358,6 +358,13 @@ function AreMandatoriesNotOk(){
 function Check(){
     var StrAlert = AreMandatoriesNotOk();
     if( ! StrAlert ){
+        var StrWarning = AreImportantsNotOk();
+        if (StrWarning){
+            var r=confirm(StrWarning);
+            if (! r){
+                return false;
+            }
+        }
         document.f.submit();
         return true;
     } else {
@@ -367,6 +374,113 @@ function Check(){
 }
 
 /** 
+ * check if mandatory subfields are written
+ */
+function AreImportantsNotOk(){
+    var importants = new Array();
+    var importantsfields = new Array();
+    var tab = new Array();
+    var label = new Array();
+    var flag=0;
+    var tabflag= new Array();
+    [% FOREACH BIG_LOO IN BIG_LOOP %]
+    [% FOREACH innerloo IN BIG_LOO.innerloop %]
+        [% IF ( innerloo.important ) %]
+           importantsfields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]"));
+        [% END %]
+        [% FOREACH subfield_loo IN innerloo.subfield_loop %]
+            [% IF ( subfield_loo.important ) %]importants.push("[% subfield_loo.id | html %]");
+                tab.push("[% BIG_LOO.number | html %]");
+                label.push("[% subfield_loo.marc_lib | html %]");
+                [% END %]
+            [% END %]
+        [% END %]
+    [% END %]
+    var StrWarning = _("A few important fields are not filled:");
+    StrWarning += "\n\n";
+    for(var i=0,len=importants.length; i<len ; i++){
+        var tag=importants[i].substr(4,3);
+        var subfield=importants[i].substr(17,1);
+        var tagnumber=importants[i].substr(19,importants[i].lastIndexOf("_")-19);
+        tabflag[tag+subfield+tagnumber]=new Array();
+        tabflag[tag+subfield+tagnumber][0]=0;
+        if( ! document.getElementById(importants[i]).value){
+            tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ;
+            document.getElementById(importants[i]).setAttribute('class','important_subfield_not_filled');
+            document.getElementById(importants[i]).focus();
+            tabflag[tag+subfield+tagnumber][1]=label[i];
+            tabflag[tag+subfield+tagnumber][2]=tab[i];
+        } else {
+            tabflag[tag+subfield+tagnumber][0] = 1;
+        }
+    }
+    for (var tagsubfieldid in tabflag){
+      if (tabflag[tagsubfieldid][0]==0){
+        var tag=tagsubfieldid.substr(0,3);
+        var subfield=tagsubfieldid.substr(3,1);
+        StrWarning += "\t* "+_("tag ")+tag+_(" subfield ")+subfield+" "+tabflag[tagsubfieldid][1]+_(" in tab ")+tabflag[tagsubfieldid][2]+"\n";
+        //StrAlert += "\t* "+label[i]+_(" in tab ")+tab[i]+"\n";
+        flag=1;
+      }
+    }
+
+    /* Check for mandatories field(not subfields) */
+    for(var i=0,len=importantsfields.length; i<len; i++){
+        isempty  = true;
+        arr      = importantsfields[i];
+        divid    = "tag_" + arr[0] + "_" + arr[1];
+        varegexp = new RegExp("^tag_" + arr[0] + "_code_");
+
+        if(parseInt(arr[0]) >= 10){
+           elem = document.getElementById(divid);
+           eleminputs = elem.getElementsByTagName('input');
+           for(var j=0,len2=eleminputs.length; j<len2; j++){
+
+              if(eleminputs[j].name.match(varegexp) && eleminputs[j].value){
+                 inputregexp = new RegExp("^tag_" + arr[0] + "_subfield_" + eleminputs[j].value + "_" + arr[2]);
+
+                   for( var k=0; k<len2; k++){
+                        if(eleminputs[k].id.match(inputregexp) && eleminputs[k].value){
+                            isempty = false
+                        }
+                    }
+
+                    elemselect = elem.getElementsByTagName('select');
+                    for( var k=0; k<elemselect.length; k++){
+                        if(elemselect[k].id.match(inputregexp) && elemselect[k].value){
+                           isempty = false
+                        }
+                    }
+              }
+           }
+
+           elemtextareas = elem.getElementsByTagName('textarea');
+           for(var j=0,len2=elemtextareas.length; j<len2; j++){
+                // this bit assumes that the only textareas in this context would be for subfields
+               if (elemtextareas[j].value) {
+                   isempty = false;
+               }
+           }
+       }else{
+          isempty = false;
+       }
+
+       if(isempty){
+          flag = 1;
+          StrWarning += _("\t* Field ") + arr[0] + _(" is important, at least one of its subfields should be filled.") + "\n";
+       }
+    }
+
+    StrWarning += "\n" + _("Are you sure you want to save?");
+
+    if(flag){
+        return StrWarning;
+    } else {
+        return flag;
+    }
+}
+
+/**
  * check if z3950 mandatories are set or not
  */
 function GetZ3950Terms(){
@@ -585,6 +699,11 @@ function Changefwk() {
                 <a href="#" tabindex="1" class="tagnum" title="[% innerloo.tag_lib | html %] - Click to Expand this Tag" onclick="ExpandField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;">[% innerloo.tag | html %]</a>
             [% ELSE %]
                 <span class="tagnum" title="[% innerloo.tag_lib | html %]">[% innerloo.tag | html %]</span>
+                [% IF innerloo.mandatory %]
+                    <span class="mandatory_marker" title="This field is mandatory">*</span>
+                [% ELSIF innerloo.important %]
+                    <span title="This field is important">*</span>
+                [% END %]
                 [% IF marcflavour != 'NORMARC' %]<a href="#" class="marcdocs" onclick="PopupMARCFieldDoc('[% innerloo.tag | html %]'); return false;">&nbsp;?</a>[% END %]
             [% END %]
                 [% IF ( innerloo.fixedfield ) %]
@@ -667,7 +786,11 @@ function Changefwk() {
                 [% UNLESS advancedMARCEditor %]
                     [% IF ( subfield_loo.mandatory ) %]<span class="subfield subfield_mandatory">[% ELSE %]<span class="subfield">[% END %]
                         [% subfield_loo.marc_lib | $raw %]
-                        [% IF ( subfield_loo.mandatory ) %]<span class="mandatory_marker" title="This field is mandatory">*</span>[% END %]
+                        [% IF ( subfield_loo.mandatory ) %]
+                        <span class="mandatory_marker" title="This field is mandatory">*</span>
+                        [% ELSIF ( subfield_loo.important ) %]
+                        <span class="important_marker" title="This field is important">*</span>
+                        [% END %]
                     </span>
                     </label>
                 [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
index 2820c4c..2468128 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
@@ -89,8 +89,10 @@ $(document).ready(function(){
 });
 
 function Check(f) {
-    var total_errors = CheckMandatorySubfields(f);
-    if (total_errors==0) {
+    var total_mandatory = CheckMandatorySubfields(f);
+    var total_important = CheckImportantSubfields(f);
+    var alertString2;
+    if (total_mandatory==0) {
         // Explanation about this line:
         // In case of limited edition permission, we have to prevent user from modifying some fields.
         // But there is no such thing as readonly attribute for select elements.
@@ -98,12 +100,27 @@ function Check(f) {
         // So we "un-disable" the elements just before submitting.
         // That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that.
         $("select[name=field_value]").prop('disabled', false);
-        return true;
     } else {
-        var alertString2 = _("Form not submitted because of the following problem(s)");
+        alertString2 = _("Form not submitted because of the following problem(s)");
         alertString2 += "\n------------------------------------------------------------------------------------\n";
-        alertString2 += "\n- " + _("%s mandatory fields empty (highlighted)").format(total_errors);
-        alert(alertString2);
+        alertString2 += "\n- " + _("%s mandatory fields empty (highlighted)").format(total_mandatory);
+    }
+    if(total_important > 0){
+        if( !alertString2 ){
+            alertString2 = "";
+        }
+        alertString2 += "\n\n " + _("%s important field(s) empty (highlighted)").format(total_important);
+        alertString2 += "\n\n " + _("Are you sure you want to save?");
+    }
+    if(alertString2){
+        if(total_mandatory){
+             alert(alertString2);
+        }else{
+            var a = confirm(alertString2);
+            if( a ){
+                return true;
+            }
+        }
         return false;
     }
     return true;
@@ -318,12 +335,15 @@ function confirm_deletion() {
                 <input type="hidden" name="tag"       value="[% ite.tag | html %]" />
                 <input type="hidden" name="subfield"  value="[% ite.subfield | html %]" />
                 <input type="hidden" name="mandatory" value="[% ite.mandatory | html %]" />
+                <input type="hidden" name="important" value="[% ite.important | html %]" />
                 [% IF ( ite.repeatable ) %]
                     <a href="#" class="buttonPlus" onclick="CloneItemSubfield(this.parentNode); return false;">
                         <img src="[% interface | html %]/[% theme | html %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
                     </a>
                 [% END %]
-                [% IF ( ite.mandatory ) %] <span class="required">Required</span>[% END %]
+                [% IF ( ite.mandatory ) %] <span class="required">Required</span>
+                [% ELSIF ( ite.important ) %] <span class="important" style="font-style: italic; margin-left: .5em;">Important</span>
+                [% END %]
             </div></li>
         [% END %]
     </ol>
diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js
index b685c2a..7a417b4 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js
@@ -557,6 +557,18 @@ function CheckMandatorySubfields(p){
     return total;
 }
 
+function CheckImportantSubfields(p){
+    var total = 0;
+    $(p).find(".subfield_line input[name='important'][value='1']").each(function(i){
+        var editor = $(this).siblings("[name='field_value']");
+        if (!editor.val()) {
+            editor.addClass("missing");
+            total++;
+        }
+    });
+    return total;
+}
+
  $(document).ready(function() {
     $("input.input_marceditor, input.indicator").addClass('noEnterSubmit');
 });
-- 
2.7.4