View | Details | Raw Unified | Return to bug 17855
Collapse All | Expand All

(-)a/installer/onboarding.pl (-106 / +33 lines)
Lines 22-59 use Modern::Perl; Link Here
22
use diagnostics;
22
use diagnostics;
23
use C4::InstallAuth;
23
use C4::InstallAuth;
24
use CGI qw ( -utf8 );
24
use CGI qw ( -utf8 );
25
use List::MoreUtils qw/uniq/;
26
use Digest::MD5 qw(md5_base64);
25
use Digest::MD5 qw(md5_base64);
27
use Encode qw( encode );
26
use Encode qw( encode );
28
use C4::Koha;
27
use C4::Koha;
29
use C4::Context;
30
use C4::Output;
28
use C4::Output;
31
use C4::Form::MessagingPreferences;
32
use C4::Members;
29
use C4::Members;
33
use C4::Members::Attributes;
30
use C4::Members::Attributes;
34
use C4::Members::AttributeTypes;
31
use C4::Members::AttributeTypes;
35
use C4::Log;
32
use C4::Log;
36
use C4::Letters;
37
use C4::Form::MessagingPreferences;
38
use Koha::AuthorisedValues;
33
use Koha::AuthorisedValues;
39
use Koha::Patron::Debarments;
34
use Koha::Patron::Debarments;
40
use Koha::Cities;
41
use Koha::Patrons;
35
use Koha::Patrons;
42
use Koha::Items;
36
use Koha::Items;
43
use Koha::Libraries;
37
use Koha::Libraries;
44
use Koha::LibraryCategories;
45
use Koha::Database;
38
use Koha::Database;
46
use Koha::DateUtils;
39
use Koha::DateUtils;
47
use Koha::Patron::Categories;
40
use Koha::Patron::Categories;
48
use Koha::Patron::Category;
41
use Koha::Patron::Category;
49
use Koha::Patron::HouseboundRole;
42
use Koha::Patron::HouseboundRole;
50
use Koha::Patron::HouseboundRoles;
43
use Koha::Patron::HouseboundRoles;
51
use Koha::Token;
52
use Email::Valid;
53
use Module::Load;
54
use Koha::ItemTypes;
44
use Koha::ItemTypes;
55
use Koha::IssuingRule;
45
use Koha::IssuingRule;
56
use Koha::IssuingRules;
46
use Koha::IssuingRules;
47
use Data::Dumper;
57
48
58
#Setting variables
49
#Setting variables
59
my $input = new CGI;
50
my $input = new CGI;
Lines 92-100 my $dbh = DBI->connect( Link Here
92
);
83
);
93
84
94
#Store the value of the template input name='op' in the variable $op so we can check if the user has pressed the button with the name="op" and value="finish" meaning the user has finished the onboarding tool.
85
#Store the value of the template input name='op' in the variable $op so we can check if the user has pressed the button with the name="op" and value="finish" meaning the user has finished the onboarding tool.
95
my $op = $input->param('op') || "";
86
my $op = $input->param('op') || '';
96
$template->param( 'op' => $op );
87
$template->param( 'op' => $op );
97
88
89
my $schema = Koha::Database->new()->schema();
90
98
if ( $op && $op eq 'finish' )
91
if ( $op && $op eq 'finish' )
99
{ #If the value of $op equals 'finish' then redirect user to /cgi-bin/koha/mainpage.pl
92
{ #If the value of $op equals 'finish' then redirect user to /cgi-bin/koha/mainpage.pl
100
    print $input->redirect("/cgi-bin/koha/mainpage.pl");
93
    print $input->redirect("/cgi-bin/koha/mainpage.pl");
Lines 242-249 elsif ( $step && $step == 2 ) { Link Here
242
    #Create a patron
235
    #Create a patron
243
}
236
}
244
elsif ( $step && $step == 3 ) {
237
elsif ( $step && $step == 3 ) {
245
    my $firstpassword  = $input->param('password') || "";
238
    my $firstpassword  = $input->param('password') || '';
246
    my $secondpassword = $input->param('password2') || "";
239
    my $secondpassword = $input->param('password2') || '';
247
240
248
241
249
    #Find all patron records in the database and hand them to the template
242
    #Find all patron records in the database and hand them to the template
Lines 281-293 elsif ( $step && $step == 3 ) { Link Here
281
    my $categories = Koha::Patron::Categories->search();
274
    my $categories = Koha::Patron::Categories->search();
282
    $template->param( 'categories' => $categories, );
275
    $template->param( 'categories' => $categories, );
283
276
277
#Incrementing the highest existing patron cardnumber to prevent duplicate cardnumber entry
284
278
279
    my $existing_cardnumber = $schema->resultset('Borrower')->get_column('cardnumber')->max();
285
280
286
281
    my $new_cardnumber = $existing_cardnumber + 1;
287
#Incrementing the highest existing patron cardnumber to prevent duplicate cardnumber entry
288
    my $exisiting_cardnumber = my $sth_search =
289
      $dbh->prepare("SELECT MAX(cardnumber) FROM borrowers");
290
    my $new_cardnumber = $exisiting_cardnumber + 1;
291
    $template->param( "newcardnumber" => $new_cardnumber );
282
    $template->param( "newcardnumber" => $new_cardnumber );
292
283
293
    my $op = $input->param('op') // 'list';
284
    my $op = $input->param('op') // 'list';
Lines 386-392 elsif ( $step && $step == 3 ) { Link Here
386
            $newdata{address}        = "";
377
            $newdata{address}        = "";
387
            $newdata{city}           = "";
378
            $newdata{city}           = "";
388
379
389
#Determine the dateexpiry of the patron based on the patron category it is created from
380
#Hand tne the dateexpiry of the patron based on the patron category it is created from
390
            my $patron_category = Koha::Patron::Categories->find( $newdata{categorycode} );
381
            my $patron_category = Koha::Patron::Categories->find( $newdata{categorycode} );
391
            $newdata{dateexpiry} = $patron_category->get_expiry_date( $newdata{dateenrolled} );
382
            $newdata{dateexpiry} = $patron_category->get_expiry_date( $newdata{dateenrolled} );
392
383
Lines 415-434 elsif ( $step && $step == 3 ) { Link Here
415
                }
406
                }
416
407
417
                # construct flags
408
                # construct flags
418
                my $module_flags = 0;
409
                my @userflags = $schema->resultset('Userflag')->search({},{
419
                my $sth =
410
                        order_by => { -asc =>'bit'},
420
                  $dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
411
                        }
421
                $sth->execute();
412
                );
422
                while ( my ( $bit, $flag ) = $sth->fetchrow_array ) {
423
                    if ( exists $all_module_perms{$flag} ) {
424
                        $module_flags += 2**$bit;
425
                    }
426
                }
427
413
428
#Set the superlibrarian permission of the newly created patron to superlibrarian
414
#Setting superlibrarian permissions for new patron
429
                $sth = $dbh->prepare(
415
                my $flags = Koha::Patrons->find($borrowernumber)->set({flags=>1})->store;
430
                    "UPDATE borrowers SET flags=? WHERE borrowernumber=?");
431
                $sth->execute( $module_flags, $borrowernumber );
432
416
433
                #Error handling checking if the patron was created successfully
417
                #Error handling checking if the patron was created successfully
434
                if ( !$borrowernumber ) {
418
                if ( !$borrowernumber ) {
Lines 581-669 elsif ( $step && $step == 5 ) { Link Here
581
565
582
        my @messages;
566
        my @messages;
583
567
584
#New code from smart-rules.tt starts here. Needs to be added to library
585
#Allows for the 'All' option to work when selecting all libraries for a circulation rule to apply to.
568
#Allows for the 'All' option to work when selecting all libraries for a circulation rule to apply to.
586
        if ( $branch eq "*" ) {
569
        if ( $branch eq "*" ) {
587
            my $sth_search = $dbh->prepare(
570
            my $search_default_rules = $schema->resultset('DefaultCircRule')->count();
588
                "SELECT count(*) AS total
571
            my $insert_default_rules = $schema->resultset('Issuingrule')->new(
589
                                        FROM default_circ_rules"
572
                    { maxissueqty => $maxissueqty, onshelfholds => $onshelfholds }
590
            );
573
                );
591
            my $sth_insert = $dbh->prepare(
592
                "INSERT INTO default_circ_rules
593
                                        (maxissueqty, onshelfholds)
594
                                        VALUES (?, ?)"
595
            );
596
            my $sth_update = $dbh->prepare(
597
                "UPDATE default_circ_rules
598
                                        SET maxissueqty = ?, onshelfholds = ?"
599
            );
600
601
            $sth_search->execute();
602
            my $res = $sth_search->fetchrow_hashref();
603
            if ( $res->{total} ) {
604
                $sth_update->execute( $maxissueqty, $onshelfholds );
605
            }
606
            else {
607
                $sth_insert->execute( $maxissueqty, $onshelfholds );
608
            }
609
        }
574
        }
610
611
#Allows for the 'All' option to work when selecting all patron categories for a circulation rule to apply to.
575
#Allows for the 'All' option to work when selecting all patron categories for a circulation rule to apply to.
612
        if ( $bor eq "*" ) {
576
        elsif ( $bor eq "*" ) {
613
            my $sth_search = $dbh->prepare(
614
                "SELECT count(*) AS total
615
                                            FROM default_circ_rules"
616
            );
617
            my $sth_insert = $dbh->prepare(
618
                q|
619
                INSERT INTO default_circ_rules
620
                    (maxissueqty)
621
                    VALUES (?)
622
            |
623
            );
624
            my $sth_update = $dbh->prepare(
625
                q|
626
                UPDATE default_circ_rules
627
                SET maxissueqty = ?
628
            |
629
            );
630
577
631
            $sth_search->execute();
578
            my $search_default_rules = $schema->resultset('DefaultCircRule')->count();
632
            my $res = $sth_search->fetchrow_hashref();
579
            my $insert_default_rules = $schema->resultset('Issuingrule')->new(
633
            if ( $res->{total} ) {
580
                        { maxissueqty => $maxissueqty}
634
                $sth_update->execute($maxissueqty);
581
            );
635
            }
636
            else {
637
                $sth_insert->execute($maxissueqty);
638
            }
639
        }
582
        }
640
583
641
#Allows for the 'All' option to work when selecting all itemtypes for a circulation rule to apply to
584
#Allows for the 'All' option to work when selecting all itemtypes for a circulation rule to apply to
642
        if ( $itemtype eq "*" ) {
585
        elsif ( $itemtype eq "*" ) {
643
            my $sth_search = $dbh->prepare(
586
            my $search_default_rules = $schema->resultset('DefaultCircRule')->search({},{
644
                "SELECT count(*) AS total
587
                    branchcode => $branch
645
                                        FROM default_branch_circ_rules
588
                    }
646
                                        WHERE branchcode = ?"
589
647
            );
648
            my $sth_insert = $dbh->prepare(
649
                "INSERT INTO default_branch_circ_rules
650
                                        (branchcode, onshelfholds)
651
                                        VALUES (?, ?)"
652
            );
653
            my $sth_update = $dbh->prepare(
654
                "UPDATE default_branch_circ_rules
655
                                        SET onshelfholds = ?
656
                                        WHERE branchcode = ?"
657
            );
590
            );
658
            $sth_search->execute($branch);
659
            my $res = $sth_search->fetchrow_hashref();
660
591
661
            if ( $res->{total} ) {
592
            my $insert_default_rules = $schema->resultset('Issuingrule')->new(
662
                $sth_update->execute( $onshelfholds, $branch );
593
                           { branchcode => $branch, onshelfholds => $onshelfholds }
663
            }
594
            );
664
            else {
665
                $sth_insert->execute( $branch, $onshelfholds );
666
            }
667
        }
595
        }
668
596
669
        my $issuingrule = Koha::IssuingRules->find(
597
        my $issuingrule = Koha::IssuingRules->find(
670
- 

Return to bug 17855