From 207270e450bf383fecad9442f730a3c8b6ac4abc Mon Sep 17 00:00:00 2001
From: remi <remi.mayrand-provencher@inLibro.com>
Date: Fri, 31 Jul 2015 08:40:55 -0400
Subject: [PATCH] [SIGNED-OFF] Bug 8643: Removed all uses of CGI::Checkbox in
 marc_subfields_structure.pl

To test this patch :

1) Apply all patches
2) Run ./installer/data/mysql/updatedatabase.pl
3) Go to More > Administration > MARC bibliographic framework > default framework ("MARC structure")
4) Search for tag 100 > Click subfields
5) Edit the "a" field and check the "reapeatable","mandatory","important" and "Is a URL" checkboxes
6) Click save an validate that the constraints for field "a" were modified properly.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

All checkboxes work, verified on db
No errors
---
 admin/marc_subfields_structure.pl                  | 45 ++--------------------
 .../en/modules/admin/marc_subfields_structure.tt   | 34 ++++++++++++++--
 2 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl
index edfe91b..1e303d4 100755
--- a/admin/marc_subfields_structure.pl
+++ b/admin/marc_subfields_structure.pl
@@ -196,7 +196,10 @@ if ( $op eq 'add_form' ) {
         $row_data{liblibrarian} = CGI::escapeHTML( $data->{'liblibrarian'} );
         $row_data{libopac}      = CGI::escapeHTML( $data->{'libopac'} );
         $row_data{seealso}      = CGI::escapeHTML( $data->{'seealso'} );
+        $row_data{repeatable}     = $data->{'repeatable'} ? 1 : 0;
+        $row_data{mandatory}      = $data->{'mandatory'} ? 1 : 0;
         $row_data{important}      = $data->{'important'} ? 1 : 0;
+        $row_data{isurl}      = $data->{'isurl'} ? 1 : 0;
         $row_data{kohafield} = {
                     id      => "kohafield$i",
                     values  => \@kohafields,
@@ -217,28 +220,7 @@ if ( $op eq 'add_form' ) {
                     values  => \@authtypes,
                     default => $data->{'authtypecode'},
         };
-        $row_data{repeatable} = CGI::checkbox(
-            -name     => "repeatable$i",
-            -checked  => $data->{'repeatable'} ? 'checked' : '',
-            -value    => 1,
-            -label    => '',
-            -id       => "repeatable$i"
-        );
-        $row_data{mandatory} = CGI::checkbox(
-            -name     => "mandatory$i",
-            -checked  => $data->{'mandatory'} ? 'checked' : '',
-            -value    => 1,
-            -label    => '',
-            -id       => "mandatory$i"
-        );
         $row_data{hidden} = CGI::escapeHTML( $data->{hidden} );
-        $row_data{isurl}  = CGI::checkbox(
-            -name     => "isurl$i",
-            -id       => "isurl$i",
-            -checked  => $data->{'isurl'} ? 'checked' : '',
-            -value    => 1,
-            -label    => ''
-        );
         $row_data{row}    = $i;
         $row_data{link}   = CGI::escapeHTML( $data->{'link'} ); 
         push( @loop_data, \%row_data );
@@ -268,27 +250,6 @@ if ( $op eq 'add_form' ) {
                     default => "$data->{'kohafield'}",
                     };
         $row_data{hidden}     = "";
-        $row_data{repeatable} = CGI::checkbox(
-            -name     => "repeatable$i",
-            -id       => "repeatable$i",
-            -checked  => '',
-            -value    => 1,
-            -label    => ''
-        );
-        $row_data{mandatory} = CGI::checkbox(
-            -name     => "mandatory$i",
-            -id       => "mandatory$i",
-            -checked  => '',
-            -value    => 1,
-            -label    => ''
-        );
-        $row_data{isurl} = CGI::checkbox(
-            -name     => "isurl$i",
-            -id       => "isurl$i",
-            -checked  => '',
-            -value    => 1,
-            -label    => ''
-        );
         $row_data{value_builder} = {
                     id      => "value_builder$i",
                     values  => \@value_builder,
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 226c09b..b7303ca 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
@@ -227,8 +227,26 @@ function populateHiddenCheckboxes(tab) {
                 		[% END %]
                 		<li><label for="liblibrarian[% loo.row %]">Text for librarian: </label><input id="liblibrarian[% loo.row %]" type="text" name="liblibrarian" value="[% loo.liblibrarian %]" size="40" maxlength="80" /></li>
                 		<li><label for="libopac[% loo.row %]">Text for OPAC: </label><input type="text" id="libopac[% loo.row %]" name="libopac" value="[% loo.libopac %]" size="40" maxlength="80" /></li>
-                		<li><label for="repeatable[% loo.row %]">Repeatable: </label>[% loo.repeatable %]</li>
-                		<li><label for="mandatory[% loo.row %]">Mandatory: </label>[% loo.mandatory %]</li>
+                        <li>
+                            <label for="repeatable[% loo.row %]"> Repeatable: </label>
+                            <label>
+                            [% IF loo.repeatable %]
+                            <input id="repeatable[% loo.row %]" type="checkbox" value="1" name="repeatable[% loo.row %]" checked="checked"/>
+                            [% ELSE %]
+                            <input id="repeatable[% loo.row %]" type="checkbox" value="1" name="repeatable[% loo.row %]"/>
+                            [% END %]
+                            </label>
+                        </li>
+                        <li>
+                            <label for="mandatory[% loo.row %]"> Mandatory: </label>
+                            <label>
+                            [% IF loo.mandatory %]
+                            <input id="mandatory[% loo.row %]" type="checkbox" value="1" name="mandatory[% loo.row %]" checked="checked"/>
+                            [% ELSE %]
+                            <input id="mandatory[% loo.row %]" type="checkbox" value="1" name="mandatory[% loo.row %]"/>
+                            [% END %]
+                            </label>
+                        </li>
                         <li>
                             <label for="important[% loo.row %]"> Important: </label>
                             <label>
@@ -285,7 +303,17 @@ function populateHiddenCheckboxes(tab) {
                     <input type="checkbox" id="hidden_flagged_[% loo.row %]" name="flagged_[% loo.row %]"/>
                     <label for="hidden_flagged_[% loo.row %]" style="float: none;">Flagged</label>
                 </li>
-                <li><label for="isurl[% loo.row %]">Is a URL:</label>[% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)</li>
+                <li>
+                    <label for="isurl[% loo.row %]"> Is a URL: </label>
+                    <label>
+                    [% IF loo.isurl %]
+                    <input id="isurl[% loo.row %]" type="checkbox" value="1" name="isurl[% loo.row %]" checked="checked"/>
+                    [% ELSE %]
+                    <input id="isurl[% loo.row %]" type="checkbox" value="1" name="isurl[% loo.row %]"/>
+                    [% END %]
+                    </label>
+                    (if checked, it means that the subfield is a URL and can be clicked)
+                </li>
                 <li><label for="link[% loo.row %]">Link:</label><input type="text" id="link[% loo.row %]" name="link" value="[% loo.link %]" size="10" maxlength="80" /> (e.g., Title or Local-Number) <span class="error"><em>NOTE: If you change this value you must ask your administrator to run misc/batchRebuildBiblioTables.pl.</em></span></li>
                 <li>
                     <label for="kohafield[% loo.row %]">Koha link:</label>
-- 
1.9.1