From f635c1c0a194bd46d15915bc548a1e61663186cc Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 16 Dec 2016 01:47:55 +0000 Subject: [PATCH] Bug 17855 - Working insertion of library, patron category, patron (with superlibrarian permissions asssigned), and item type Create circulation screens backend code to insert a circulation rule into the database not yet working. Bug 17855 - Same as previous patch with some minor changes to the code for step 2 (creating a patron category) in onboarding.pl Bug 17855 - Same as previous patch except made changes to the perl code for creating a patron category which is step 2 in the onboarding.pl script Bug 17855 - Successful insertion from onboarding tool of library, patron category, patron and item type. Successful checking if library, patron category and item type has been installed with web installer, and if they have been installed then the appropriate onboarding tool step is skipped. Bug 17855 - Working insertion of library, patron category and patron as well as checks for library, patron category, and item type in the onboarding tool. i.e. Very similar to the previous patch Error messages working for create library. In progress for patron category. Fixing the item type error handling. Still in progress. Correctly inserting patron so they can now log in with the patron account they create on the onboarding tool (no superlibrarian permissions yet) but the dropdown boxes on the create circulation rule screen no longer work Fixed some things I broke in patron category Fixed more of patron category. Should be working normally but error handling still not implemented. Same as previous Working insertion of the patron into the borrowers table and setting of superlibrarian permissions so the user can log in with the patron they create in the onboarding tool however the dropdown boxes in the create circulation rule screen now do not work --- installer/onboarding.pl | 212 +++++++++++---------- .../prog/en/modules/onboarding/onboardingstep1.tt | 43 +++-- .../prog/en/modules/onboarding/onboardingstep2.tt | 30 ++- .../prog/en/modules/onboarding/onboardingstep3.tt | 32 ++-- .../prog/en/modules/onboarding/onboardingstep4.tt | 46 +++-- 5 files changed, 207 insertions(+), 156 deletions(-) diff --git a/installer/onboarding.pl b/installer/onboarding.pl index aac1705..bea4e65 100755 --- a/installer/onboarding.pl +++ b/installer/onboarding.pl @@ -41,17 +41,6 @@ use Koha::Token; use Email::Valid; use Module::Load; -#Imports for item types step 4 -use Koha::ItemTypes; -use Koha::Localizations; - -#Imports for circulation rule step 5 -use Koha::IssuingRule; -use Koha::IssuingRules; -use Koha::Logger; -use Koha::RefundLostItemFeeRule; -use Koha::RefundLostItemFeeRules; - #Setting variables my $input = new CGI; my $query = new CGI; @@ -124,7 +113,6 @@ if ( $start && $start eq 'Start setting up my Koha' ){ }elsif ( $start && $start eq 'Add an item type' ){ my $itemtypes = Koha::ItemTypes->search(); - warn $itemtypes; $template->param( itemtypes => $itemtypes, ); @@ -139,18 +127,23 @@ if ( $start && $start eq 'Start setting up my Koha' ){ my $branchcode = $input->param('branchcode'); my $categorycode = $input->param('categorycode'); my $op = $input->param('op') || 'list'; - my @messages; + my $message; my $library; +#my @messages; #Take the text 'branchname' and store it in the @fields array my @fields = qw( branchname ); + +#test + $template->param('branchcode'=>$branchcode); + $branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode #Create a new library object and store the branchcode and @fields array values in this new library object - my $library = Koha::Library->new( + $library = Koha::Library->new( { branchcode => $branchcode, ( map { $_ => scalar $input->param($_) || undef } @fields ) } @@ -158,22 +151,28 @@ if ( $start && $start eq 'Start setting up my Koha' ){ eval { $library->store; }; #Use the eval{} function to store the library object - #If there are values in the $@ then push the values type => 'alert', code => 'error_on_insert' into the @messages array el se push the values type => 'message', code => 'success_on_insert' to that array - if ($@) { - push @messages, { type => 'alert', code => 'error_on_insert' }; - } else { - push @messages, { type => 'message', code => 'success_on_insert' }; - } + if($library){ + $message = 'success_on_insert'; + }else{ + $message = 'error_on_insert'; + } + + $template->param('message' => $message); + #Check if the $step vairable equals 2 i.e. the user has clicked to create a patron category in the create patron category screen 1 }elsif ( $step && $step == 2 ){ + my $createcat = $query->param('createcat'); #Store the inputted library branch code and name in $createlibrary + $template->param('createcat'=>$createcat); # Hand the library values back to the template in the createlibrary variable + #Initialising values my $input = new CGI; my $searchfield = $input->param('description') // q||; my $categorycode = $input->param('categorycode'); my $op = $input->param('op') // 'list'; - my @messages; + my $message; + my $category; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -185,25 +184,12 @@ if ( $start && $start eq 'Start setting up my Koha' ){ debug => 1, } ); - #When the user first arrives on the page - if ( $op eq 'add_form' ) { - my $category; - if ($categorycode) { - $category = Koha::Patron::Categories->find($categorycode); - } - - $template->param( - category => $category, - ); + - if ( C4::Context->preference('EnhancedMessagingPreferences') ) { - C4::Form::MessagingPreferences::set_form_values( - { categorycode => $categorycode }, $template ); - } - } #Once the user submits the page, this code validates the input and adds it #to the database as a new patron category - elsif ( $op eq 'add_validate' ) { +#} elsif ( $op eq 'add_validate' ) { + my $categorycode = $input->param('categorycode'); my $description = $input->param('description'); my $overduenoticerequired = $input->param('overduenoticerequired'); @@ -223,7 +209,7 @@ if ( $start && $start eq 'Start setting up my Koha' ){ ); } #Adds to the database - my $category = Koha::Patron::Category->new({ + $category = Koha::Patron::Category->new({ categorycode=> $categorycode, description => $description, overduenoticerequired => $overduenoticerequired, @@ -236,13 +222,15 @@ if ( $start && $start eq 'Start setting up my Koha' ){ $category->store; }; - #Error messages - if($@){ - push @messages, {type=> 'error', code => 'error_on_insert'}; + #Error messages + if($category){ + $message = 'success_on_insert'; }else{ - push @messages, {type=> 'message', code => 'success_on_insert'}; + $message = 'error_on_insert'; } - } + + $template->param('message' => $message); + #Create a patron }elsif ( $step && $step == 3 ){ @@ -258,73 +246,101 @@ if ( $start && $start eq 'Start setting up my Koha' ){ ] ); - my $categories; - $categories= Koha::Patron::Categories->search(); - $template->param( - categories => $categories, - ); - + my $categories; + $categories= Koha::Patron::Categories->search(); + $template->param( + categories => $categories, + ); my $input = new CGI; - my $op = $input->param('op'); + my $op = $input->param('op') // 'list'; + my @messages; - my ($template, $loggedinuser, $cookie) - = get_template_and_user({ + my ($template, $loggedinuser, $cookie)= get_template_and_user({ template_name => "/onboarding/onboardingstep3.tt", query => $input, type => "intranet", authnotrequired => 0, flagsrequired => {borrowers => 1}, debug => 1, - }); + }); if($op eq 'add_form'){ my $member; $template->param( member => $member, ); - - } + elsif($op eq 'add_validate'){ - my $surname => $input->param('surname'); - my $firstname => $input->param('firstname'); - my $cardnumber => $input->param('cardnumber'); - my $libraries => $input->param('libraries'); - my $categorycode_entry => $input->param('categorycode_entry'); - my $userid => $input->param('userid'); - my $password => $input->param('password'); - my $password2 =>$input->param('password2'); - - my $member = Koha::Patron->new({ - surname => $surname, - firstname => $firstname, - cardnumber => $cardnumber, - libraries => $libraries, - categorycode_entry => $categorycode_entry, - userid => $userid, - password => $password, - password2 => $password2, - }); - eval { - $member->store; - }; - if($@){ + + my %newdata; + +#Store the template form values in the newdata hash + $newdata{borrowernumber} = $input->param('borrowernumber'); + $newdata{surname} = $input->param('surname'); + $newdata{firstname} = $input->param('firstname'); + $newdata{cardnumber} = $input->param('cardnumber'); + $newdata{branchcode} = $input->param('libraries'); + $newdata{categorycode} = $input->param('categorycode_entry'); + $newdata{userid} = $input->param('userid'); + $newdata{password} = $input->param('password'); + $newdata{password2} = $input->param('password2'); + $newdata{dateexpiry} = '12/10/2016'; + +#Hand the newdata hash to the AddMember subroutine in the C4::Members module and it creates a patron and hands back a borrowernumber which is being stored + my $borrowernumber = &AddMember(%newdata); + my %member2; + $member2{'borrowernumber'}=$borrowernumber; + + my $flag = $input->param('flag'); + + if ($input->param('newflags')) { + my $dbh=C4::Context->dbh(); + my @perms = $input->multi_param('flag'); + my %all_module_perms = (); + my %sub_perms = (); + foreach my $perm (@perms) { + if ($perm !~ /:/) { + $all_module_perms{$perm} = 1; + } else { + my ($module, $sub_perm) = split /:/, $perm, 2; + push @{ $sub_perms{$module} }, $sub_perm; + } + } + + + # construct flags + my $module_flags = 0; + my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit"); + $sth->execute(); + while (my ($bit, $flag) = $sth->fetchrow_array) { + if (exists $all_module_perms{$flag}) { + $module_flags += 2**$bit; + } + } + + $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?"); + $sth->execute($module_flags, $borrowernumber); + + +#Error handling checking if the patron was created successfully + if(!$borrowernumber){ push @messages, {type=> 'error', code => 'error_on_insert'}; - }else{ + }else{ push @messages, {type=> 'message', code => 'success_on_insert'}; - } - + } } - -#Create item type }elsif ( $step && $step == 4){ + my $createitemtype = $input->param('createitemtype'); + $template->param('createitemtype'=> $createitemtype ); + my $input = new CGI; my $itemtype_code = $input->param('itemtype'); my $op = $input->param('op') // 'list'; - my @messages; + my $message; my( $template, $borrowernumber, $cookie) = get_template_and_user( { template_name => "/onboarding/onboardingstep4.tt", @@ -338,7 +354,7 @@ if ( $start && $start eq 'Start setting up my Koha' ){ if($op eq 'add_form'){ my $itemtype = Koha::ItemTypes->find($itemtype_code); - template->param(itemtype=>$itemtype,); + $template->param(itemtype=> $itemtype,); }elsif($op eq 'add_validate'){ my $itemtype = Koha::ItemTypes->find($itemtype_code); my $description = $input->param('description'); @@ -351,11 +367,13 @@ if ( $start && $start eq 'Start setting up my Koha' ){ ); eval{ $itemtype->store; }; #Error messages - if($@){ - push @messages, {type=> 'error', code => 'error_on_insert'}; + if($itemtype){ + $message = 'success_on_insert'; }else{ - push @messages, {type=> 'message', code => 'success_on_insert'}; + $message = 'error_on_insert'; } + + $template->param('message' => $message); } }elsif ( $step && $step == 5){ @@ -381,12 +399,12 @@ if ( $start && $start eq 'Start setting up my Koha' ){ flagsrequired=> {parameters => 'manage_circ_rules'}, debug =>1, }); - + my $type = $input->param('type'); my $branch = $input->param('branch'); - - - + + + if($op eq 'add_form'){ @@ -418,17 +436,13 @@ if ( $start && $start eq 'Start setting up my Koha' ){ }else{ Koha::IssuingRule->new()->set($params)->store(); } - - } - - - + my $createcirculationrule = $query->param('createcirculationrule'); + $template->param('createcirculationrule'=>$createcirculationrule); } - - +} output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep1.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep1.tt index 92f741b..07d0809 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep1.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep1.tt @@ -52,30 +52,37 @@ [% ELSIF (createlibrary) %] -
- -

New Library

-
-

Success: Library created!

-

To add another library and for more settings,
- go to Tools->Administration->Libraries and Groups -

- Next up: - -
- - + [% IF message == "success_on_insert" %] +
+ +

New Library

+
+

Success: Library created! Your branchcode is [% branchcode %]

+

To add another library and for more settings,
+ go to Tools->Administration->Libraries and Groups +

+ Next up: + +
+ + [%ELSE %] + +
+ +

Failed

+
+

Library was not successfully created
+ Please try again or contact your system administrator.

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

Create a Library

-
  1. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep2.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep2.tt index ebad7d3..5808346 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep2.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep2.tt @@ -18,6 +18,8 @@ var MSG_ONE_ENROLLMENTPERIOD = ("Please choose an enrollment period in months OR by date."); + +
    @@ -37,18 +39,32 @@ -[% ELSIF op == 'add_validate' %] -
    - +[% ELSIF op == "add_validate" %] + [% IF message != "error_on_insert" %] + + Message is [%message%] +

    New patron category

    -

    Success: Patron category created!

    +

    Success: Patron category created! Your patron category code is [% category.categorycode %]

    To add another patron category and for more settings
    go to More->Administration->Patrons & Circulation->Patron Categories

    Next up:
    + [% ELSE %] +
    + Message is [% message %] + +

    Failed

    +
    Patron Category was not successfully created.
    + Please try again or contact your system administrator.

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

    Create a new Patron Category

    @@ -85,12 +101,6 @@
  2. New Patron

    -

    Success: New patron created!

    To create another patron, go to Patrons > New Patron.
    @@ -54,7 +53,8 @@

    Patron Identity

  3. - + + Required
  4. @@ -74,10 +74,10 @@
  5. - [% FOREACH library IN libraries %] -
  6. - + [% FOREACH category IN categories %] + + [% END %] Required
-
    + +
      + +

      Patron permissions

      + +
    1. + + +
    2. +
    +

      OPAC/Staff Login

    1. @@ -101,8 +111,8 @@ Required
    2. - - + + Required
    3. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep4.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep4.tt index a4f0dab..380488f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep4.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep4.tt @@ -20,7 +20,9 @@ [% IF itemtypes.count > 0 %]
      -

      You do not need to create a item type as you have already installed the sample item type data previously

      + h no! Patron was not created

      + +

      You do not need to create a item type as you have already installed the sample item type data previously

      @@ -32,26 +34,34 @@ [% ELSIF op == "add_validate" %] - - -

      New Item type

      - -
      -

      Success: New item type created!

      -

      To create another item type later and for more setttings
      - go to More->Administration->Item types -

      - Next up: - - + [% IF message != "error_on_insert" %] +
      + +

      New Item type

      + +
      +

      Success: New item type created!

      +

      To create another item type later and for more setttings
      + go to More->Administration->Item types +

      + Next up: + +
      + [% ELSE %] +
      + +

      Failed

      +
      +

      Item type was not successfully created.
      + Please try again or contact your system administrator.

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

      Create a new Item type

      -
      +
      @@ -63,7 +73,7 @@
    4. - + Required
    -- 2.1.4