From bfc8b8e59677a98599329d7f33b6b967037032cd Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sun, 29 Jan 2017 11:33:35 +0000 Subject: [PATCH] Bug 18060 - Label onboarding tool to be displayed when no labels or templates exist --- C4/Budgets.pm | 7 + C4/Creators/Layout.pm | 13 ++ C4/Creators/Profile.pm | 11 ++ C4/Creators/Template.pm | 11 ++ acqui/acqui-home.pl | 24 +++ admin/aqbudgetperiods.pl | 8 +- admin/aqbudgets.pl | 12 +- admin/currency.pl | 9 + koha-tmpl/intranet-tmpl/prog/css/staff-global.css | 5 + .../prog/en/includes/budgets-active-currency.inc | 16 +- .../prog/en/includes/onboardinginclude1.inc | 200 +++++++++++++++++++++ .../prog/en/includes/onboardinginclude2.inc | 162 +++++++++++++++++ .../prog/en/includes/onboardinginclude3.inc | 75 ++++++++ .../prog/en/modules/acqui/acqui-home.tt | 48 ++++- .../prog/en/modules/admin/aqbudgetperiods.tt | 2 +- .../prog/en/modules/admin/aqbudgets.tt | 3 +- .../prog/en/modules/labels/label-home.tt | 8 +- labels/label-edit-layout.pl | 31 +++- labels/label-edit-template.pl | 11 +- labels/label-home.pl | 70 ++++++++ 20 files changed, 702 insertions(+), 24 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude1.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude2.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude3.inc diff --git a/C4/Budgets.pm b/C4/Budgets.pm index c68fbec..13d6ecd 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -146,6 +146,13 @@ sub GetPeriodsCount { } # ------------------------------------------------------------------- + +sub GetHighestBudgetPeriod{ + my $dbh = C4::Context->dbh; + warn my $data = $dbh->selectrow_array("SELECT MAX(budget_period_id) FROM aqbudgetperiods"); + return $data; +} +# ------------------------------------------------------------------- sub CheckBudgetParent { my ( $new_parent, $budget ) = @_; my $new_parent_id = $new_parent->{'budget_id'}; diff --git a/C4/Creators/Layout.pm b/C4/Creators/Layout.pm index f1dc20e..e806499 100644 --- a/C4/Creators/Layout.pm +++ b/C4/Creators/Layout.pm @@ -8,6 +8,7 @@ use autouse 'Data::Dumper' => qw(Dumper); use C4::Context; use C4::Debug; use C4::Creators::PDF; +use C4::Creators; # FIXME: Consider this style parameter verification instead... @@ -111,6 +112,17 @@ sub retrieve { return $self; } +sub retrieve_all { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select count(*) from creator_layouts where creator = 'Labels' group by creator"); + my $layout = $sth->execute(); + if ($layout == '0E0'){ + return 0; + } else { + return $layout; + } +} + sub delete { my $self = {}; my %opts = (); @@ -234,6 +246,7 @@ sub get_text_wrap_cols { return $col_count; } + 1; __END__ diff --git a/C4/Creators/Profile.pm b/C4/Creators/Profile.pm index 37512fa..ba82145 100644 --- a/C4/Creators/Profile.pm +++ b/C4/Creators/Profile.pm @@ -90,6 +90,17 @@ sub retrieve { return $self; } +sub retrieve_all { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select count(*) from printers_profile where creator = 'Labels' group by creator"); + my $profile = $sth->execute(); + if ($profile == '0E0'){ + return 0; + } else { + return $profile; + } +} + sub delete { my $self = {}; my %opts = (); diff --git a/C4/Creators/Template.pm b/C4/Creators/Template.pm index ee504d7..87240b9 100644 --- a/C4/Creators/Template.pm +++ b/C4/Creators/Template.pm @@ -131,6 +131,17 @@ sub retrieve { return $self; } +sub retrieve_all { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select count(*) FROM creator_templates ct where creator = 'Labels' group by creator"); + my $templatecount = $sth->execute(); + if ($templatecount == '0E0'){ + return 0; + } else { + return $templatecount; + } +} + sub delete { my $self = {}; my %opts = (); diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl index fe53174..56b68de 100755 --- a/acqui/acqui-home.pl +++ b/acqui/acqui-home.pl @@ -122,11 +122,35 @@ $template->param( suggestions_count => $suggestions_count, ); + + + + + +my $aqstep; my $cur = Koha::Acquisition::Currencies->get_active; + if ( $cur ) { $template->param( currency => $cur->currency, ); } +my $budget = GetPeriodsCount(); +my $budgetid = C4::Budgets->GetHighestBudgetPeriod(); +if (!@budget_loop){ +if (!$cur) { + $aqstep = 1; + $template->param( step => $aqstep ); +} elsif ($budget && $budgetid == 1){ + $aqstep = 3; + $template->param( step => $aqstep ); +} elsif ($budgetid > 1) { + print $query->redirect("/cgi-bin/koha/admin/aqbudgetperiods.pl"); + exit; +} else { + $aqstep = 2; + $template->param( step => $aqstep ); +} +} output_html_with_http_headers $query, $cookie, $template->output; diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index ca2171f..26a2881 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -113,14 +113,18 @@ if ( $op eq 'add_form' ) { elsif ( $op eq 'add_validate' ) { ## add or modify a budget period (confirmation) - ## update budget period data +## update budget period data if ( $budget_period_id ne '' ) { $$budget_period_hashref{$_}||=0 for qw(budget_period_active budget_period_locked); my $status=ModBudgetPeriod($budget_period_hashref); } else { # ELSE ITS AN ADD my $budget_period_id=AddBudgetPeriod($budget_period_hashref); - } + my $stepfund = $input->param( 'step' ); + $template->param( stepfund => $stepfund ); + print $input->redirect("/cgi-bin/koha/acqui/acqui-home.pl"); + exit; +} $op='else'; } diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 97664df..5e51a48 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -76,8 +76,6 @@ my $budget_permission = $input->param('budget_permission'); my $budget_users_ids = $input->param('budget_users_ids'); my $filter_budgetbranch = $input->param('filter_budgetbranch') // ''; my $filter_budgetname = $input->param('filter_budgetname'); - - # ' ------- get periods stuff ------------------' # IF PERIODID IS DEFINED, GET THE PERIOD - ELSE JUST GET THE ACTIVE PERIOD BY DEFAULT my $period; @@ -180,6 +178,7 @@ if ($op eq 'add_form') { # END $OP eq ADD_FORM #---------------------- DEFAULT DISPLAY BELOW --------------------- + # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { @@ -221,6 +220,15 @@ if ($op eq 'add_form') { $budget_hash->{budget_id} = AddBudget( $budget_hash ); ModBudgetUsers($budget_hash->{budget_id}, @budgetusersid); $budget_modified = 1; + + my $fundcreation = $input->param('fundcreation'); + + if ($fundcreation eq "onboarding"){ + my $step = $input->param('step'); + $template->param('step' => $step); + print $input->redirect("/cgi-bin/koha/acqui/acqui-home.pl"); + exit; + } } my $set_owner_to_children = $input->param('set_owner_to_children'); diff --git a/admin/currency.pl b/admin/currency.pl index 1c5ec3e..c1adbb3 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -89,6 +89,15 @@ if ( $op eq 'add_form' ) { } $searchfield = q||; $op = 'list'; + + my $aqcurrency = $input->param('aqcurrency'); + if ($aqcurrency == 1) { + my $step = $input->param( 'step' ); + $template->param( step => $step ); + print $input->redirect("/cgi-bin/koha/acqui/acqui-home.pl"); + exit; + } + } elsif ( $op eq 'delete_confirm' ) { my $currency = Koha::Acquisition::Currencies->find($currency_code); diff --git a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css index fb09d51..65b232b 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css @@ -3007,3 +3007,8 @@ fieldset.rows + fieldset.action { #patron_search #filters { display: none; } +div#aqhelp{ + background-color:#EDF4F6; + padding:20px; + width:50%; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-active-currency.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-active-currency.inc index 1862059..75a018b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-active-currency.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-active-currency.inc @@ -1,14 +1,26 @@ + + [% IF ( currency ) %] [% IF ( not hide ) %]

Currency = [% currency %]

[% END %] [% ELSE %] -
+

No active currency is defined

[% IF CAN_user_parameters_parameters_remaining_permissions %]

Please specify an active currency.

[% ELSE %]

Your administrator must specify an active currency.

[% END %] -
+
[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude1.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude1.inc new file mode 100644 index 0000000..2d33777 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude1.inc @@ -0,0 +1,200 @@ + + +[% BLOCK translate_justification_types %] + [% SWITCH type %] + [% CASE 'L' %]Left + [% CASE 'C' %]Center + [% CASE 'R' %]Right + [% END %] +[% END %] + +[% BLOCK translate_label_types %] + [% SWITCH type %] + [% CASE 'BIB' %]Biblio + [% CASE 'BARBIB' %]Barcode/Biblio + [% CASE 'BIBBAR' %]Biblio/Barcode + [% CASE 'ALT' %]Alternating + [% CASE 'BAR' %]Barcode + [% END %] +[% END %] + +[% IF displayonboarding =="acqui" %] +
+

Acquisition onboarding wizard

+

This onboarding wizard will take you through the process of setting up Acquistions

+

Start by completing this form to create a currency which you will be used to create your first budget and fund.
+ A fund is the accounting value you use to create orders

+
+ + + +
+ + New currency + +
    +
  1. + [% IF currency %] + Currency: + + [% currency.currency %] + [% ELSE %] + + Required + [% END %] +
  2. +
  3. + + Required +
  4. +
  5. + + Required +
  6. +
  7. + + +
  8. +
  9. + + + +
  10. +
+
+
+ +
+
+
+ +[% ELSIF displayonboarding == "label" %] +
+
+
+ [% IF ( layout_id ) %]Edit[% ELSE %]Create[% END %] label layout +
    +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + + +
  6. +
  7. +
    + Bibliographic data to print +
      +
    1. [% IF ( layout_string ) %] + + [% ELSE %] + + [% END %] +
      +

      + [% FOREACH text_field IN fields %] +   +    + [% END %] +

      +
      +
    +
  8. +
  9. + + [% IF ( guidebox ) %] + + [% ELSE %] + + [% END %] +
  10. +
  11. + + [% IF ( callnum_split ) %] + + [% ELSE %] + + [% END %] +
  12. +
  13. + + +
  14. +
  15. + + +
  16. +
  17. + + +
  18. +
  19. + + [% IF ( oblique_title ) %] + + [% ELSE %] + + [% END %] +
  20. +
+ +
+ + Cancel + + + +
+ +
+[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude2.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude2.inc new file mode 100644 index 0000000..da4304b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude2.inc @@ -0,0 +1,162 @@ + +
+ [% IF displayonboarding == "acquisitions" %] +

Acquisition onboarding wizard

+

Create a budget which is the highest level value in acquisitions accountancy.
+ After creating this budget you will be prompted to create a fund which is what you will use to set up orders. +

+ If you have previously created a budget (which was subsequently deleted) then you will be redirected to the Budget Administration page after creating a budget using this form. On the Budget Administration page click Actions->Add fund to create a fund +

Create a budget

+
+
+ + + +
    +
  1. + + +
    [% INCLUDE 'date-format.inc' %]
    +
  2. + +
  3. + + +
    [% INCLUDE 'date-format.inc' %]
    +
  4. + +
  5. + + +
  6. + +
  7. + + +
  8. + +
  9. + + +
  10. +
+
+
+ + + +
+
+ [% ELSIF displayonboarding == "label" %] +
+
+
    +
  1. + Template ID:[% IF ( template_id ) %][% template_id %][% ELSE %]N/A[% END %] +
  2. +
  3. + + +
  4. +
  5. + + +
  6. +
  7. + + +
  8. +
  9. + + +
  10. +
  11. + + +
  12. +
  13. + + +
  14. +
  15. + + +
  16. +
+
+
+
  1. + + +
  2. +
  3. + + +
  4. +
  5. + + +
  6. +
  7. + + +
  8. +
  9. + + +
  10. +
  11. + + +
  12. +
  13. + + +
  14. +
  15. + + +
  16. + +
  17. + + [% IF ( profile_list ) %] + + [% ELSE %] + Click here to define a printer profile. + [% END %] +
  18. +
+ Cancel + + [% IF ( template_id ) %] + + [% END %] +
+
+[% END %] +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude3.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude3.inc new file mode 100644 index 0000000..6097fcf --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/onboardinginclude3.inc @@ -0,0 +1,75 @@ + + +
+ [% IF displayonboarding == "label" %] +

Acquisition onboarding wizard

+

Fill out this form to create a fund which will be assigned to the budget you just created.
+ A fund is an accounting value you will use to set up orders

+
+

Create a fund

+
+ + + + + [% IF ( budget_id ) %] + + [% END %] + [% budget_id %] + +
+ [% IF ( budget_id ) %]Modify[% ELSE %]Add[% END %] Fund + [% IF ( budget_period_description ) %] + [% budget_name %] for Budget '[% budget_period_description %]' + [% END %] + +
    + [% budget_parent_id = 0 %] +
  1. + Fund parent: + [% budget_parent_name %] + [% budget_parent_id %] - [% budget_parent_name %] + +
  2. +
  3. + + +
  4. + +
  5. + + +
  6. + +
  7. + + +
  8. + + + + [% IF ( budget_id ) %] + + [% END %] + +
+
+ + +
+
+[% END %] +
+ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt index f64a60b..70bcd09 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt @@ -1,19 +1,28 @@ [% USE Price %] [% USE Branches %] +[% USE Koha %] +[% USE KohaDates %] +[% USE Branches %] + [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions [% INCLUDE 'doc-head-close.inc' %] + [% INCLUDE 'datatables.inc' %] +[% INCLUDE 'calendar.inc' %] + + @@ -98,15 +111,21 @@ $(document).ready(function() {
[% INCLUDE 'acquisitions-toolbar.inc' %] - -

Acquisitions

- [% INCLUDE 'budgets-active-currency.inc' hide = 'yes' %] [% UNLESS ( loop_budget ) %] [% IF ( CAN_user_acquisition_period_manage ) %] - + [% displayonboarding = "acquisitions" %] + [% IF step == 1 %] + [% INCLUDE onboardinginclude1.inc %] + [% ELSIF step == 2 %] + [% INCLUDE onboardinginclude2.inc %] + [% ELSIF step == 3 %] + [% INCLUDE onboardinginclude3.inc %] + [% END %] [% ELSE %]
Your administrator must define a budget in Administration
[% END %] + [% ELSE %] +

Acquisitions

[% END %]
@@ -237,6 +256,27 @@ $(document).ready(function() {
[% END %] + +

+
+

Next steps

+

1. Create your first vendor

+

A vendor is the organisation your institution purchases items from i.e. suppliers
+ You must create a vendor before you can create any orders

+ Click here to create a vendor. +

+

2. Create your first basket

+

A basket is the conceptual container that holds orders. Each basket is assigned to a single vendor so you can perform multiple seperate orders from a single vendor simultaneously. Because of its reliance on vendor the basket must be created after the vendor

+ To create a basket, click the 'New basket' button on the Vendor Information page which is displayed after you create a vendor +

+

3. Create an order

+

An order is a assignment of items purchased from a single vendor at a single time

+ You create an order by clicking "Add to basket" in the Basket page. From here you can choose the item(s) you want to purchase from existing MARC records in your Koha catalogue, subscription, new item record, external source, staged file (bibliographic file in the process of being uploaded), or from popularly held items. +

+

+ For further information about creating a vendor, basket and order go to the Koha manual: + Koha manual Acquisitions section +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt index 76f0701..acf8b97 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt @@ -334,7 +334,7 @@
  • -
    [% INCLUDE 'date-format.inc' %]
    +
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index a3c9ee9..87350c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -453,7 +453,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") -[% IF op == 'add_form' && !error_not_authorised_to_modify %] +[% IF op == 'add_form' %]
    [% IF ( budget_id ) %]Modify[% ELSE %]Add[% END %] Fund @@ -464,6 +464,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") +
      [% IF ( budget_parent_id ) %]
    1. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-home.tt index f5e7725..c20ccce 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-home.tt @@ -20,7 +20,13 @@
      [% INCLUDE 'labels-toolbar.inc' %]
      - + [% IF !(layoutvalue) %] + [% displayonboarding = "label" %] + [% INCLUDE 'onboardinginclude1.inc' %] + [% ELSIF !(templatevalue) %] + [% displayonboarding = "label" %] + [% INCLUDE 'onboardinginclude2.inc' %] + [% END %]
  • diff --git a/labels/label-edit-layout.pl b/labels/label-edit-layout.pl index c1aafd4..8ee664c 100755 --- a/labels/label-edit-layout.pl +++ b/labels/label-edit-layout.pl @@ -123,20 +123,32 @@ elsif ($op eq 'save') { $layout = C4::Labels::Layout->new(@params); $layout_id = $layout->save(); } - print $cgi->redirect("label-manage.pl?label_element=layout" . ($layout_id == -1 ? "&element_id=$layout_id&op=$op&error=1" : '')); - exit; + + my $layoutvalue = C4::Creators::Layout->retrieve_all(); + my $templatecount = C4::Creators::Template->retrieve_all(); + $template->param( layoutvalue => $layoutvalue, + templatevalue => $templatecount, + ); + + if ($templatecount == 0) { + print $cgi->redirect("/cgi-bin/koha/labels/label-home.pl"); + exit; + } else { + print $cgi->redirect("label-manage.pl?label_element=layout" . ($layout_id == -1 ? "&element_id=$layout_id&op=$op&error=1" : '')); + exit; + } } else { # if we get here, this is a new layout $layout = C4::Labels::Layout->new(); } -my $barcode_types = _set_selected(get_barcode_types(), $layout, 'barcode_type'); -my $label_types = _set_selected(get_label_types(), $layout, 'printing_type'); -my $font_types = _set_selected(get_font_types(), $layout, 'font'); -my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify'); -my ($select_text_fields, $select_text_fields_cnt) = _select_format_string($layout->get_attr('format_string')); + my $barcode_types = _set_selected(get_barcode_types(), $layout, 'barcode_type'); + my $label_types = _set_selected(get_label_types(), $layout, 'printing_type'); + my $font_types = _set_selected(get_font_types(), $layout, 'font'); + my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify'); + my ($select_text_fields, $select_text_fields_cnt) = _select_format_string($layout->get_attr('format_string')); -$template->param( + $template->param( barcode_types => $barcode_types, label_types => $label_types, font_types => $font_types, @@ -151,5 +163,6 @@ $template->param( callnum_split => $layout->get_attr('callnum_split'), format_string => $layout->get_attr('format_string'), layout_string => 1, # FIXME: This should not be hard-coded; It should perhaps be yet another syspref... CN -); + ); + output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/labels/label-edit-template.pl b/labels/label-edit-template.pl index bcee714..d7d891b 100755 --- a/labels/label-edit-template.pl +++ b/labels/label-edit-template.pl @@ -111,8 +111,15 @@ elsif ($op eq 'save') { $profile->save(); } } - print $cgi->redirect("label-manage.pl?label_element=template"); - exit; + + my $profilevalue = C4::Creators::Profile->retrieve_all(); + if ($profilevalue == 0) { + print $cgi->redirect("label-edit-profile.pl"); + exit; + }else{ + print $cgi->redirect("/cgi-bin/koha/labels/label-home.pl"); + exit; + } } else { # if we get here, this is a new layout $label_template = C4::Labels::Template->new(); diff --git a/labels/label-home.pl b/labels/label-home.pl index ca581ac..4c5645b 100755 --- a/labels/label-home.pl +++ b/labels/label-home.pl @@ -22,9 +22,14 @@ use strict; use warnings; use CGI qw ( -utf8 ); +use POSIX; use C4::Auth qw(get_template_and_user); use C4::Output qw(output_html_with_http_headers); +use C4::Creators::Layout; +use C4::Creators::Template; +use C4::Creators; +use C4::Labels; my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -38,4 +43,69 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); +my $op = $cgi->param('op') || ''; +my $layout_id = $cgi->param('layout_id') || $cgi->param('element_id') || ''; +my $layout_choice = $cgi->param('layout_choice') || ''; +my $layout = C4::Labels::Layout->new(); + +sub _set_selected { + my ($type_list, $object, $data_type) = @_; + SET_SELECTED: + foreach my $type (@$type_list) { + if ($layout->get_attr($data_type)) { + if ($type->{'type'} eq $layout->get_attr($data_type)) { + $type->{'selected'} = 1; + } + } + else { + $type->{'selected'} = 1; + last SET_SELECTED; + } +}; +return $type_list; +} + +sub _select_format_string { # generate field table based on format_string + my $format_string = shift; + + my @text_fields = grep /\w/, split /\s*,\s/, $format_string; + my %tf = map {$_ => 1} @text_fields; + my @missing_fields = grep { !$tf{$_} } @{ C4::Labels::Layout->PRESET_FIELDS }; + my $field_count = scalar(@text_fields) + scalar( @missing_fields); + + my @fields; + my $field_index = 1; + foreach my $f (@text_fields) { + push @fields, {field_name => ($f . "_tbl"), field_label => $f, order => $field_index}; + $field_index++; + } + foreach my $f (@missing_fields) { + push @fields, {field_name => ($f . "_tbl"), field_label => $f}; + } + return (\@fields, $field_count); +} + +my $barcode_types = _set_selected(get_barcode_types(), $layout, 'barcode_type'); +my $label_types = _set_selected(get_label_types(), $layout, 'printing_type'); +my $font_types = _set_selected(get_font_types(), $layout, 'font'); +my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify'); +my ($select_text_fields, $select_text_fields_cnt) = _select_format_string($layout->get_attr('format_string')); +my $units = get_unit_values(); + +$template->param( + barcode_types => $barcode_types, + label_types => $label_types, + font_types => $font_types, + text_justification_types => $text_justification_types, + fields => $select_text_fields, + field_count => $select_text_fields_cnt, + units => $units, +); + +my $layoutvalue = C4::Creators::Layout->retrieve_all(); +my $templatevalue = C4::Creators::Template->retrieve_all(); +$template->param( layoutvalue => $layoutvalue, + templatevalue => $templatevalue, +); + output_html_with_http_headers $cgi, $cookie, $template->output; -- 2.1.4