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

(-)a/installer/install.pl (-159 / +205 lines)
Lines 1-21 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
# #
4
#
5
# # Copyright (C) YEAR  YOURNAME-OR-YOUREMPLOYER
5
# Copyright (C) YEAR  YOURNAME-OR-YOUREMPLOYER
6
# #
6
#
7
# # Koha is free software; you can redistribute it and/or modify it
7
# Koha is free software; you can redistribute it and/or modify it
8
# # under the terms of the GNU General Public License as published by
8
# under the terms of the GNU General Public License as published by
9
# # the Free Software Foundation; either version 3 of the License, or
9
# the Free Software Foundation; either version 3 of the License, or
10
# # (at your option) any later version.
10
# (at your option) any later version.
11
# #
11
#
12
# # Koha is distributed in the hope that it will be useful, but
12
# Koha is distributed in the hope that it will be useful, but
13
# # WITHOUT ANY WARRANTY; without even the implied warranty of
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# # GNU General Public License for more details.
15
# GNU General Public License for more details.
16
# #
16
#
17
# # You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use strict;
21
use warnings;
21
use warnings;
Lines 57-66 if ( defined($language) ) { Link Here
57
my $installer = C4::Installer->new();
57
my $installer = C4::Installer->new();
58
my %info;
58
my %info;
59
$info{'dbname'} = C4::Context->config("database");
59
$info{'dbname'} = C4::Context->config("database");
60
$info{'dbms'} =
60
$info{'dbms'}   = (
61
  (   C4::Context->config("db_scheme")
61
      C4::Context->config("db_scheme")
62
    ? C4::Context->config("db_scheme")
62
    ? C4::Context->config("db_scheme")
63
    : "mysql" );
63
    : "mysql"
64
);
64
$info{'hostname'} = C4::Context->config("hostname");
65
$info{'hostname'} = C4::Context->config("hostname");
65
$info{'port'}     = C4::Context->config("port");
66
$info{'port'}     = C4::Context->config("port");
66
$info{'user'}     = C4::Context->config("user");
67
$info{'user'}     = C4::Context->config("user");
Lines 72-83 my $dbh = DBI->connect( Link Here
72
);
73
);
73
74
74
if ( $step && $step == 1 ) {
75
if ( $step && $step == 1 ) {
76
75
    #First Step (for both fresh installations and upgrades)
77
    #First Step (for both fresh installations and upgrades)
76
    #Checking ALL perl Modules and services needed are installed.
78
    #Checking ALL perl Modules and services needed are installed.
77
    #Whenever there is an error, adding a report to the page
79
    #Whenever there is an error, adding a report to the page
78
    my $op = $query->param('op') || 'noop';
80
    my $op = $query->param('op') || 'noop';
79
    $template->param( language => 1 );
81
    $template->param( language      => 1 );
80
    $template->param( 'checkmodule' => 1 ); # we start with the assumption that there are no problems and set this to 0 if there are
82
    $template->param( 'checkmodule' => 1 )
83
      ; # we start with the assumption that there are no problems and set this to 0 if there are
81
84
82
    unless ( $] >= 5.010000 ) {    # Bug 7375
85
    unless ( $] >= 5.010000 ) {    # Bug 7375
83
        $template->param( problems => 1, perlversion => 1, checkmodule => 0 );
86
        $template->param( problems => 1, perlversion => 1, checkmodule => 0 );
Lines 87-97 if ( $step && $step == 1 ) { Link Here
87
    $perl_modules->version_info;
90
    $perl_modules->version_info;
88
91
89
    my $modules = $perl_modules->get_attr('missing_pm');
92
    my $modules = $perl_modules->get_attr('missing_pm');
90
    if (scalar(@$modules)) {
93
    if ( scalar(@$modules) ) {
91
        my @components = ();
94
        my @components  = ();
92
        my $checkmodule = 1;
95
        my $checkmodule = 1;
93
        foreach (@$modules) {
96
        foreach (@$modules) {
94
            my ($module, $stats) = each %$_;
97
            my ( $module, $stats ) = each %$_;
95
            $checkmodule = 0 if $stats->{'required'};
98
            $checkmodule = 0 if $stats->{'required'};
96
            push(
99
            push(
97
                @components,
100
                @components,
Lines 103-116 if ( $step && $step == 1 ) { Link Here
103
                }
106
                }
104
            );
107
            );
105
        }
108
        }
106
        @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
109
        @components = sort { $a->{'name'} cmp $b->{'name'} } @components;
107
        $template->param( missing_modules => \@components, checkmodule => $checkmodule, op => $op );
110
        $template->param(
111
            missing_modules => \@components,
112
            checkmodule     => $checkmodule,
113
            op              => $op
114
        );
108
    }
115
    }
109
}
116
}
110
elsif ( $step && $step == 2 ) {
117
elsif ( $step && $step == 2 ) {
111
#
118
112
#STEP 2 Check Database connection and access
119
    #STEP 2 Check Database connection and access
113
#
120
114
    $template->param(%info);
121
    $template->param(%info);
115
    my $checkdb = $query->param("checkdb");
122
    my $checkdb = $query->param("checkdb");
116
    $template->param( 'dbconnection' => $checkdb );
123
    $template->param( 'dbconnection' => $checkdb );
Lines 135-141 elsif ( $step && $step == 2 ) { Link Here
135
                my $grantaccess;
142
                my $grantaccess;
136
                while ( my ($line) = $rq->fetchrow ) {
143
                while ( my ($line) = $rq->fetchrow ) {
137
                    my $dbname = $info{dbname};
144
                    my $dbname = $info{dbname};
138
                    if ( $line =~ m/^GRANT (.*?) ON `$dbname`\.\*/ || index( $line, '*.*' ) > 0 ) {
145
                    if ( $line =~ m/^GRANT (.*?) ON `$dbname`\.\*/
146
                        || index( $line, '*.*' ) > 0 )
147
                    {
139
                        $grantaccess = 1
148
                        $grantaccess = 1
140
                          if (
149
                          if (
141
                            index( $line, 'ALL PRIVILEGES' ) > 0
150
                            index( $line, 'ALL PRIVILEGES' ) > 0
Lines 170-192 elsif ( $step && $step == 2 ) { Link Here
170
                    }
179
                    }
171
                }
180
                }
172
                $template->param( "checkgrantaccess" => $grantaccess );
181
                $template->param( "checkgrantaccess" => $grantaccess );
173
            }	# End mysql connect check...
182
            }    # End mysql connect check...
183
184
            elsif ( $info{dbms} eq "Pg" ) {
174
185
175
	    elsif ( $info{dbms} eq "Pg" ) {
186
                # Check if database has been created...
176
		# Check if database has been created...
187
                my $rv = $dbh->do(
177
		my $rv = $dbh->do( "SELECT * FROM pg_catalog.pg_database WHERE datname = \'$info{dbname}\';" );
188
"SELECT * FROM pg_catalog.pg_database WHERE datname = \'$info{dbname}\';"
178
		if ( $rv == 1 )	{
189
                );
179
			$template->param( 'checkdatabasecreated' => 1 );
190
                if ( $rv == 1 ) {
180
		}
191
                    $template->param( 'checkdatabasecreated' => 1 );
192
                }
181
193
182
		# Check if user has all necessary grants on this database...
194
                # Check if user has all necessary grants on this database...
183
		my $rq = $dbh->do( "SELECT u.usesuper
195
                my $rq = $dbh->do(
196
                    "SELECT u.usesuper
184
				    FROM pg_catalog.pg_user as u
197
				    FROM pg_catalog.pg_user as u
185
				    WHERE u.usename = \'$info{user}\';" );
198
				    WHERE u.usename = \'$info{user}\';"
186
		if ( $rq == 1 ) {
199
                );
187
			$template->param( "checkgrantaccess" => 1 );
200
                if ( $rq == 1 ) {
188
		}
201
                    $template->param( "checkgrantaccess" => 1 );
189
            }	# End Pg connect check...
202
                }
203
            }    # End Pg connect check...
190
        }
204
        }
191
        else {
205
        else {
192
            $template->param( "error" => DBI::err, "message" => DBI::errstr );
206
            $template->param( "error" => DBI::err, "message" => DBI::errstr );
Lines 194-204 elsif ( $step && $step == 2 ) { Link Here
194
    }
208
    }
195
}
209
}
196
elsif ( $step && $step == 3 ) {
210
elsif ( $step && $step == 3 ) {
197
#
211
198
#
212
    # STEP 3 : database setup
199
# STEP 3 : database setup
213
200
#
201
#
202
    my $op = $query->param('op');
214
    my $op = $query->param('op');
203
    if ( $op && $op eq 'finished' ) {
215
    if ( $op && $op eq 'finished' ) {
204
        #
216
        #
Lines 210-228 elsif ( $step && $step == 3 ) { Link Here
210
    elsif ( $op && $op eq 'finish' ) {
222
    elsif ( $op && $op eq 'finish' ) {
211
        $installer->set_version_syspref();
223
        $installer->set_version_syspref();
212
224
213
        # Installation is finished.
225
# Installation is finished.
214
        # We just deny anybody access to install
226
# We just deny anybody access to install
215
        # And we redirect people to mainpage.
227
# And we redirect people to mainpage.
216
        # The installer will have to relogin since we do not pass cookie to redirection.
228
# The installer will have to relogin since we do not pass cookie to redirection.
217
        $template->param( "$op" => 1 );
229
        $template->param( "$op" => 1 );
218
    }
230
    }
219
231
220
    elsif ( $op && $op eq 'addframeworks' ) {
232
    elsif ( $op && $op eq 'addframeworks' ) {
221
    #
222
    # 1ST install, 3rd sub-step : insert the SQL files the user has selected
223
    #
224
233
225
        my ($fwk_language, $list) = $installer->load_sql_in_order($all_languages, $query->param('framework'));
234
        # 1ST install, 3rd sub-step : insert the SQL files the user has selected
235
236
        my ( $fwk_language, $list ) =
237
          $installer->load_sql_in_order( $all_languages,
238
            $query->param('framework') );
226
        $template->param(
239
        $template->param(
227
            "fwklanguage" => $fwk_language,
240
            "fwklanguage" => $fwk_language,
228
            "list"        => $list
241
            "list"        => $list
Lines 232-276 elsif ( $step && $step == 3 ) { Link Here
232
        $template->param( "$op" => 1 );
245
        $template->param( "$op" => 1 );
233
    }
246
    }
234
    elsif ( $op && $op eq 'selectframeworks' ) {
247
    elsif ( $op && $op eq 'selectframeworks' ) {
235
        #
248
#
236
        #
249
#
237
        # 1ST install, 2nd sub-step : show the user the sql datas he can insert in the database.
250
# 1ST install, 2nd sub-step : show the user the sql datas he can insert in the database.
238
        #
251
#
239
        #
252
#
240
        # (note that the term "selectframeworks is not correct. The user can select various files, not only frameworks)
253
# (note that the term "selectframeworks is not correct. The user can select various files, not only frameworks)
241
254
242
        #Framework Selection
255
#Framework Selection
243
        #sql data for import are supposed to be located in installer/data/<language>/<level>
256
#sql data for import are supposed to be located in installer/data/<language>/<level>
244
        # Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
257
# Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
245
        # Where <level> is a category of requirement : required, recommended optional
258
# Where <level> is a category of requirement : required, recommended optional
246
        # level should contain :
259
# level should contain :
247
        #   SQL File for import With a readable name.
260
#   SQL File for import With a readable name.
248
        #   txt File that explains what this SQL File is meant for.
261
#   txt File that explains what this SQL File is meant for.
249
        # Could be VERY useful to have A Big file for a kind of library.
262
# Could be VERY useful to have A Big file for a kind of library.
250
        # But could also be useful to have some Authorised values data set prepared here.
263
# But could also be useful to have some Authorised values data set prepared here.
251
        # Framework Selection is achieved through checking boxes.
264
# Framework Selection is achieved through checking boxes.
252
        my $langchoice = $query->param('fwklanguage');
265
        my $langchoice = $query->param('fwklanguage');
253
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
266
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
254
	$langchoice =~ s/[^a-zA-Z_-]*//g;
267
        $langchoice =~ s/[^a-zA-Z_-]*//g;
255
        my $marcflavour = $query->param('marcflavour');
268
        my $marcflavour = $query->param('marcflavour');
256
        if ($marcflavour){
269
        if ($marcflavour) {
257
            $installer->set_marcflavour_syspref($marcflavour);
270
            $installer->set_marcflavour_syspref($marcflavour);
258
        };
271
        }
259
        $marcflavour = C4::Context->preference('marcflavour') unless ($marcflavour);
272
        $marcflavour = C4::Context->preference('marcflavour')
273
          unless ($marcflavour);
274
260
        #Insert into database the selected marcflavour
275
        #Insert into database the selected marcflavour
261
        undef $/;
276
        undef $/;
262
        my ($marc_defaulted_to_en, $fwklist) = $installer->marc_framework_sql_list($langchoice, $marcflavour);
277
        my ( $marc_defaulted_to_en, $fwklist ) =
263
        $template->param('en_marc_frameworks' => $marc_defaulted_to_en);
278
          $installer->marc_framework_sql_list( $langchoice, $marcflavour );
264
        $template->param( "frameworksloop" => $fwklist );
279
        $template->param( 'en_marc_frameworks' => $marc_defaulted_to_en );
265
        $template->param( "marcflavour" => ucfirst($marcflavour));
280
        $template->param( "frameworksloop"     => $fwklist );
266
281
        $template->param( "marcflavour"        => ucfirst($marcflavour) );
267
        my ($sample_defaulted_to_en, $levellist) = $installer->sample_data_sql_list($langchoice);
282
268
        $template->param( "en_sample_data" => $sample_defaulted_to_en);
283
        my ( $sample_defaulted_to_en, $levellist ) =
269
        $template->param( "levelloop" => $levellist );
284
          $installer->sample_data_sql_list($langchoice);
270
        $template->param( "$op"       => 1 );
285
        $template->param( "en_sample_data" => $sample_defaulted_to_en );
286
        $template->param( "levelloop"      => $levellist );
287
        $template->param( "$op"            => 1 );
271
288
272
        my $setup = $query->param('setup');
289
        my $setup = $query->param('setup');
273
        $template->param( "setup"=> $setup );
290
        $template->param( "setup" => $setup );
274
291
275
    }
292
    }
276
    elsif ( $op && $op eq 'choosemarc' ) {
293
    elsif ( $op && $op eq 'choosemarc' ) {
Lines 280-326 elsif ( $step && $step == 3 ) { Link Here
280
        #
297
        #
281
        #
298
        #
282
299
283
        #Choose Marc Flavour
300
#Choose Marc Flavour
284
        #sql data are supposed to be located in installer/data/<dbms>/<language>/marcflavour/marcflavourname
301
#sql data are supposed to be located in installer/data/<dbms>/<language>/marcflavour/marcflavourname
285
	# Where <dbms> is database type according to DBD syntax
302
# Where <dbms> is database type according to DBD syntax
286
        # Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
303
# Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
287
        # Where <level> is a category of requirement : required, recommended optional
304
# Where <level> is a category of requirement : required, recommended optional
288
        # level should contain :
305
# level should contain :
289
        #   SQL File for import With a readable name.
306
#   SQL File for import With a readable name.
290
        #   txt File taht explains what this SQL File is meant for.
307
#   txt File taht explains what this SQL File is meant for.
291
        # Could be VERY useful to have A Big file for a kind of library.
308
# Could be VERY useful to have A Big file for a kind of library.
292
        # But could also be useful to have some Authorised values data set prepared here.
309
# But could also be useful to have some Authorised values data set prepared here.
293
        # Marcflavour Selection is achieved through radiobuttons.
310
# Marcflavour Selection is achieved through radiobuttons.
294
        my $langchoice = $query->param('fwklanguage');
311
        my $langchoice = $query->param('fwklanguage');
295
312
296
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
313
        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
297
	$langchoice =~ s/[^a-zA-Z_-]*//g;
314
        $langchoice =~ s/[^a-zA-Z_-]*//g;
298
        my $dir =
315
        my $dir =
299
          C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/$langchoice/marcflavour";
316
          C4::Context->config('intranetdir')
300
        unless (opendir( MYDIR, $dir )) {
317
          . "/installer/data/$info{dbms}/$langchoice/marcflavour";
301
            if ($langchoice eq 'en') {
318
        unless ( opendir( MYDIR, $dir ) ) {
319
            if ( $langchoice eq 'en' ) {
302
                warn "cannot open MARC frameworks directory $dir";
320
                warn "cannot open MARC frameworks directory $dir";
303
            } else {
321
            }
322
            else {
304
                # if no translated MARC framework is available,
323
                # if no translated MARC framework is available,
305
                # default to English
324
                # default to English
306
                $dir = C4::Context->config('intranetdir') . "/installer/data/$info{dbms}/en/marcflavour";
325
                $dir = C4::Context->config('intranetdir')
307
                opendir(MYDIR, $dir) or warn "cannot open English MARC frameworks directory $dir";
326
                  . "/installer/data/$info{dbms}/en/marcflavour";
327
                opendir( MYDIR, $dir )
328
                  or warn "cannot open English MARC frameworks directory $dir";
308
            }
329
            }
309
        }
330
        }
310
        my @listdir = grep { !/^\./ && -d "$dir/$_" } readdir(MYDIR);
331
        my @listdir = grep { !/^\./ && -d "$dir/$_" } readdir(MYDIR);
311
        closedir MYDIR;
332
        closedir MYDIR;
312
        my $marcflavour=C4::Context->preference("marcflavour");
333
        my $marcflavour = C4::Context->preference("marcflavour");
313
        my @flavourlist;
334
        my @flavourlist;
314
        foreach my $marc (@listdir) {
335
        foreach my $marc (@listdir) {
315
            my %cell=(
336
            my %cell = (
316
            "label"=> ucfirst($marc),
337
                "label"   => ucfirst($marc),
317
            "code"=>uc($marc),
338
                "code"    => uc($marc),
318
            "checked"=> defined($marcflavour) ? uc($marc) eq $marcflavour : 0);
339
                "checked" => defined($marcflavour)
340
                ? uc($marc) eq $marcflavour
341
                : 0
342
            );
343
319
#             $cell{"description"}= do { local $/ = undef; open INPUT "<$dir/$marc.txt"||"";<INPUT> };
344
#             $cell{"description"}= do { local $/ = undef; open INPUT "<$dir/$marc.txt"||"";<INPUT> };
320
            push @flavourlist, \%cell;
345
            push @flavourlist, \%cell;
321
        }
346
        }
322
        $template->param( "flavourloop" => \@flavourlist );
347
        $template->param( "flavourloop" => \@flavourlist );
323
        $template->param( "$op"       => 1 );
348
        $template->param( "$op"         => 1 );
324
    }
349
    }
325
    elsif ( $op && $op eq 'importdatastructure' ) {
350
    elsif ( $op && $op eq 'importdatastructure' ) {
326
        #
351
        #
Lines 340-346 elsif ( $step && $step == 3 ) { Link Here
340
        #
365
        #
341
        #Do updatedatabase And report
366
        #Do updatedatabase And report
342
367
343
        if ( ! defined $ENV{PERL5LIB} ) {
368
        if ( !defined $ENV{PERL5LIB} ) {
344
            my $find = "C4/Context.pm";
369
            my $find = "C4/Context.pm";
345
            my $path = $INC{$find};
370
            my $path = $INC{$find};
346
            $path =~ s/\Q$find\E//;
371
            $path =~ s/\Q$find\E//;
Lines 348-406 elsif ( $step && $step == 3 ) { Link Here
348
            warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n";
373
            warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n";
349
        }
374
        }
350
375
351
        my $now = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
376
        my $now         = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
352
        my $logdir = C4::Context->config('logdir');
377
        my $logdir      = C4::Context->config('logdir');
353
        my $dbversion = C4::Context->preference('Version');
378
        my $dbversion   = C4::Context->preference('Version');
354
        my $kohaversion = Koha::version;
379
        my $kohaversion = Koha::version;
355
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
380
        $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
356
381
357
        my $filename_suffix = join '_', $now, $dbversion, $kohaversion;
382
        my $filename_suffix = join '_', $now, $dbversion, $kohaversion;
358
        my ( $logfilepath, $logfilepath_errors ) = ( chk_log($logdir, "updatedatabase_$filename_suffix"), chk_log($logdir, "updatedatabase-error_$filename_suffix") );
383
        my ( $logfilepath, $logfilepath_errors ) = (
384
            chk_log( $logdir, "updatedatabase_$filename_suffix" ),
385
            chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
386
        );
359
387
360
        my $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors";
388
        my $cmd = C4::Context->config("intranetdir")
389
          . "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors";
361
390
362
        system($cmd );
391
        system($cmd );
363
392
364
        my $fh;
393
        my $fh;
365
        open( $fh, "<", $logfilepath ) or die "Cannot open log file $logfilepath: $!";
394
        open( $fh, "<", $logfilepath )
395
          or die "Cannot open log file $logfilepath: $!";
366
        my @report = <$fh>;
396
        my @report = <$fh>;
367
        close $fh;
397
        close $fh;
368
        if (@report) {
398
        if (@report) {
369
            $template->param( update_report => [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] );
399
            $template->param( update_report =>
400
                  [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ]
401
            );
370
            $template->param( has_update_succeeds => 1 );
402
            $template->param( has_update_succeeds => 1 );
371
        } else {
372
            eval{ `rm $logfilepath` };
373
        }
403
        }
374
        open( $fh, "<", $logfilepath_errors ) or die "Cannot open log file $logfilepath_errors: $!";
404
        else {
405
            eval { `rm $logfilepath` };
406
        }
407
        open( $fh, "<", $logfilepath_errors )
408
          or die "Cannot open log file $logfilepath_errors: $!";
375
        @report = <$fh>;
409
        @report = <$fh>;
376
        close $fh;
410
        close $fh;
377
        if (@report) {
411
        if (@report) {
378
            $template->param( update_errors => [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] );
412
            $template->param( update_errors =>
413
                  [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ]
414
            );
379
            $template->param( has_update_errors => 1 );
415
            $template->param( has_update_errors => 1 );
380
            warn "The following errors were returned while attempting to run the updatedatabase.pl script:\n";
416
            warn
417
"The following errors were returned while attempting to run the updatedatabase.pl script:\n";
381
            foreach my $line (@report) { warn "$line\n"; }
418
            foreach my $line (@report) { warn "$line\n"; }
382
        } else {
419
        }
383
            eval{ `rm $logfilepath_errors` };
420
        else {
421
            eval { `rm $logfilepath_errors` };
384
        }
422
        }
385
        $template->param( $op => 1 );
423
        $template->param( $op => 1 );
386
    }
424
    }
387
    else {
425
    else {
388
        #
426
#
389
        # check whether it's a 1st install or an update
427
# check whether it's a 1st install or an update
390
        #
428
#
391
        #Check if there are enough tables.
429
#Check if there are enough tables.
392
        # Paul has cleaned up tables so reduced the count
430
# Paul has cleaned up tables so reduced the count
393
        #I put it there because it implied a data import if condition was not satisfied.
431
#I put it there because it implied a data import if condition was not satisfied.
394
        my $dbh = DBI->connect(
432
        my $dbh = DBI->connect(
395
    		"DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}"
433
            "DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}"
396
      		. ( $info{port} ? ";port=$info{port}" : "" ),
434
              . ( $info{port} ? ";port=$info{port}" : "" ),
397
            	$info{'user'}, $info{'password'}
435
            $info{'user'}, $info{'password'}
398
        );
436
        );
399
	my $rq;
437
        my $rq;
400
        if ( $info{dbms} eq 'mysql' ) { $rq = $dbh->prepare( "SHOW TABLES" ); }
438
        if ( $info{dbms} eq 'mysql' ) { $rq = $dbh->prepare("SHOW TABLES"); }
401
	elsif ( $info{dbms} eq 'Pg' ) { $rq = $dbh->prepare( "SELECT *
439
        elsif ( $info{dbms} eq 'Pg' ) {
440
            $rq = $dbh->prepare(
441
                "SELECT *
402
								FROM information_schema.tables
442
								FROM information_schema.tables
403
								WHERE table_schema='public' and table_type='BASE TABLE';" ); }
443
								WHERE table_schema='public' and table_type='BASE TABLE';"
444
            );
445
        }
404
        $rq->execute;
446
        $rq->execute;
405
        my $data = $rq->fetchall_arrayref( {} );
447
        my $data = $rq->fetchall_arrayref( {} );
406
        my $count = scalar(@$data);
448
        my $count = scalar(@$data);
Lines 411-433 elsif ( $step && $step == 3 ) { Link Here
411
            $template->param( "count" => $count, "proposeimport" => 1 );
453
            $template->param( "count" => $count, "proposeimport" => 1 );
412
        }
454
        }
413
        else {
455
        else {
414
            #
456
           #
415
            # we have tables, propose to select files to upload or updatedatabase
457
           # we have tables, propose to select files to upload or updatedatabase
416
            #
458
           #
417
            $template->param( "count" => $count, "default" => 1 );
459
            $template->param( "count" => $count, "default" => 1 );
418
            #
460
     #
419
            # 1st part of step 3 : check if there is a databaseversion systempreference
461
     # 1st part of step 3 : check if there is a databaseversion systempreference
420
            # if there is, then we just need to upgrade
462
     # if there is, then we just need to upgrade
421
            # if there is none, then we need to install the database
463
     # if there is none, then we need to install the database
422
            #
464
     #
423
            if (C4::Context->preference('Version')) {
465
            if ( C4::Context->preference('Version') ) {
424
                my $dbversion = C4::Context->preference('Version');
466
                my $dbversion = C4::Context->preference('Version');
425
                $dbversion =~ /(.*)\.(..)(..)(...)/;
467
                $dbversion =~ /(.*)\.(..)(..)(...)/;
426
                $dbversion = "$1.$2.$3.$4";
468
                $dbversion = "$1.$2.$3.$4";
427
                $template->param("upgrading" => 1,
469
                $template->param(
428
                                "dbversion" => $dbversion,
470
                    "upgrading"   => 1,
429
                                "kohaversion" => Koha::version(),
471
                    "dbversion"   => $dbversion,
430
                                );
472
                    "kohaversion" => Koha::version(),
473
                );
431
            }
474
            }
432
        }
475
        }
433
    }
476
    }
Lines 445-451 else { Link Here
445
        if ( $rq->execute ) {
488
        if ( $rq->execute ) {
446
            my ($version) = $rq->fetchrow;
489
            my ($version) = $rq->fetchrow;
447
            if ($version) {
490
            if ($version) {
448
                print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
491
                print $query->redirect(
492
                    "/cgi-bin/koha/installer/install.pl?step=3");
449
                exit;
493
                exit;
450
            }
494
            }
451
        }
495
        }
Lines 453-465 else { Link Here
453
}
497
}
454
output_html_with_http_headers $query, $cookie, $template->output;
498
output_html_with_http_headers $query, $cookie, $template->output;
455
499
456
sub chk_log { #returns a logfile in $dir or - if that failed - in temp dir
500
sub chk_log {    #returns a logfile in $dir or - if that failed - in temp dir
457
    my ($dir, $name) = @_;
501
    my ( $dir, $name ) = @_;
458
    my $fn=$dir.'/'.$name.'.log';
502
    my $fn = $dir . '/' . $name . '.log';
459
    if( ! open my $fh, '>', $fn ) {
503
    if ( !open my $fh, '>', $fn ) {
460
        $name.= '_XXXX';
504
        $name .= '_XXXX';
461
        require File::Temp;
505
        require File::Temp;
462
        ($fh, $fn)= File::Temp::tempfile( $name, TMPDIR => 1, SUFFIX => '.log');
506
        ( $fh, $fn ) =
507
          File::Temp::tempfile( $name, TMPDIR => 1, SUFFIX => '.log' );
508
463
        #if this should not work, let croak take over
509
        #if this should not work, let croak take over
464
    }
510
    }
465
    return $fn;
511
    return $fn;
(-)a/installer/onboarding.pl (-382 / +466 lines)
Lines 1-29 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
# #
4
#
5
# # Copyright (C) YEAR  YOURNAME-OR-YOUREMPLOYER
5
# Copyright (C) YEAR  YOURNAME-OR-YOUREMPLOYER
6
# #
6
#
7
# # Koha is free software; you can redistribute it and/or modify it
7
# Koha is free software; you can redistribute it and/or modify it
8
# # under the terms of the GNU General Public License as published by
8
# under the terms of the GNU General Public License as published by
9
# # the Free Software Foundation; either version 3 of the License, or
9
# the Free Software Foundation; either version 3 of the License, or
10
# # (at your option) any later version.
10
# (at your option) any later version.
11
# #
11
#
12
# # Koha is distributed in the hope that it will be useful, but
12
# Koha is distributed in the hope that it will be useful, but
13
# # WITHOUT ANY WARRANTY; without even the implied warranty of
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# # GNU General Public License for more details.
15
# GNU General Public License for more details.
16
# #
16
#
17
# # You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
19
21
#Recommended pragmas
20
#Recommended pragmas
22
use strict;
23
use warnings;
24
use diagnostics;
25
26
use Modern::Perl;
21
use Modern::Perl;
22
use diagnostics;
27
use C4::InstallAuth;
23
use C4::InstallAuth;
28
use CGI qw ( -utf8 );
24
use CGI qw ( -utf8 );
29
use List::MoreUtils qw/uniq/;
25
use List::MoreUtils qw/uniq/;
Lines 39-45 use C4::Members::Attributes; Link Here
39
use C4::Members::AttributeTypes;
35
use C4::Members::AttributeTypes;
40
use C4::Log;
36
use C4::Log;
41
use C4::Letters;
37
use C4::Letters;
42
use C4::Form::MessagingPreferences; 
38
use C4::Form::MessagingPreferences;
43
use Koha::AuthorisedValues;
39
use Koha::AuthorisedValues;
44
use Koha::Patron::Debarments;
40
use Koha::Patron::Debarments;
45
use Koha::Cities;
41
use Koha::Cities;
Lines 60-508 use Koha::IssuingRule; Link Here
60
use Koha::IssuingRules;
56
use Koha::IssuingRules;
61
57
62
#Setting variables
58
#Setting variables
63
my $input    = new CGI;
59
my $input = new CGI;
64
my $query    = new CGI;
60
my $step  = $input->param('step');
65
my $step     = $query->param('step');
66
61
67
#Getting the appropriate template to display to the user
62
#Getting the appropriate template to display to the user
68
my ( $template, $loggedinuser, $cookie) = C4::InstallAuth::get_template_and_user(
63
my ( $template, $loggedinuser, $cookie ) =
69
     {
64
  C4::InstallAuth::get_template_and_user(
70
        template_name => "/onboarding/onboardingstep" . ( $step ? $step : 0 ) . ".tt",
65
    {
71
        query         => $query,
66
        template_name => "/onboarding/onboardingstep"
72
        type          => "intranet",
67
          . ( $step ? $step : 0 ) . ".tt",
68
        query           => $input,
69
        type            => "intranet",
73
        authnotrequired => 0,
70
        authnotrequired => 0,
74
        debug           => 1,
71
        debug           => 1,
75
    }
72
    }
76
);
73
  );
77
74
78
#Check database connection
75
#Check database connection
79
my %info;
76
my %info;
80
$info{'dbname'} = C4::Context->config("database");
77
$info{'dbname'} = C4::Context->config("database");
81
$info{'dbms'} =
78
$info{'dbms'}   = (
82
(   C4::Context->config("db_scheme")
79
      C4::Context->config("db_scheme")
83
    ? C4::Context->config("db_scheme")
80
    ? C4::Context->config("db_scheme")
84
     : "mysql" );
81
    : "mysql"
82
);
85
83
86
$info{'hostname'} = C4::Context->config("hostname");
84
$info{'hostname'} = C4::Context->config("hostname");
87
$info{'port'}     = C4::Context->config("port");
85
$info{'port'}     = C4::Context->config("port");
88
$info{'user'}     = C4::Context->config("user");
86
$info{'user'}     = C4::Context->config("user");
89
$info{'password'} = C4::Context->config("pass");
87
$info{'password'} = C4::Context->config("pass");
90
my $dbh = DBI->connect(
88
my $dbh = DBI->connect(
91
         "DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}"
89
    "DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}"
92
          . ( $info{port} ? ";port=$info{port}" : "" ),
90
      . ( $info{port} ? ";port=$info{port}" : "" ),
93
           $info{'user'}, $info{'password'}
91
    $info{'user'}, $info{'password'}
94
);
92
);
95
93
96
97
#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.
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.
98
my $op = $query->param('op');
95
my $op = $input->param('op');
99
$template->param('op'=>$op);
96
$template->param( 'op' => $op );
100
if ( $op && $op eq 'finish' ) { #If the value of $op equals 'finish' then redirect user to /cgi-bin/koha/mainpage.pl
97
if ( $op && $op eq 'finish' )
101
    print $query->redirect("/cgi-bin/koha/mainpage.pl");
98
{ #If the value of $op equals 'finish' then redirect user to /cgi-bin/koha/mainpage.pl
99
    print $input->redirect("/cgi-bin/koha/mainpage.pl");
102
    exit;
100
    exit;
103
}
101
}
104
102
105
106
#Store the value of the template input name='start' in the variable $start so we can check if the user has pressed this button and started the onboarding tool process
103
#Store the value of the template input name='start' in the variable $start so we can check if the user has pressed this button and started the onboarding tool process
107
my $start = $query->param('start');
104
my $start = $input->param('start');
108
$template->param('start'=>$start);
105
$template->param( 'start' => $start );
109
110
if ( $start && $start eq 'Start setting up my Koha' ){
111
    my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
112
    $template->param(libraries   => $libraries,
113
              group_types => [
114
                {   categorytype => 'searchdomain',
115
                    categories   => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ],
116
                },
117
                {   categorytype => 'properties',
118
                         categories   => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ],
119
                },
120
              ]
121
    );
122
106
107
if ( $start && $start eq 'Start setting up my Koha' ) {
108
    my $libraries =
109
      Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
110
    $template->param(
111
        libraries   => $libraries,
112
        group_types => [
113
            {
114
                categorytype => 'searchdomain',
115
                categories   => [
116
                    Koha::LibraryCategories->search(
117
                        { categorytype => 'searchdomain' }
118
                    )
119
                ],
120
            },
121
            {
122
                categorytype => 'properties',
123
                categories   => [
124
                    Koha::LibraryCategories->search(
125
                        { categorytype => 'properties' }
126
                    )
127
                ],
128
            },
129
        ]
130
    );
131
}
132
elsif ( $start && $start eq 'Add a patron category' ) {
123
133
124
}elsif ( $start && $start eq 'Add a patron category' ){
125
#Select all the patron category records in the categories database table and give them to the template
134
#Select all the patron category records in the categories database table and give them to the template
126
    my $categories = Koha::Patron::Categories->search();
135
    my $categories = Koha::Patron::Categories->search();
127
    $template->param(
136
    $template->param( categories => $categories, );
128
        categories => $categories,
129
    );
130
137
138
#Check if the $step variable equals 1 i.e. the user has clicked to create a library in the create library screen 1
139
}
140
elsif ( $start && $start eq 'Add an item type' ) {
131
141
132
#Check if the $step variable equals 1 i.e. the user has clicked to create a library in the create library screen 1 
142
    my $itemtypes = Koha::ItemTypes->search();
133
}elsif ( $step && $step == 1 ) {
143
    $template->param( itemtypes => $itemtypes, );
134
    my $createlibrary = $query->param('createlibrary'); #Store the inputted library branch code and name in $createlibrary variable
144
}
135
    $template->param('createlibrary'=>$createlibrary); # Hand the library values back to the template in the createlibrary variable
145
elsif ( $step && $step == 1 ) {
146
    my $createlibrary = $input->param('createlibrary'); #Store the inputted library branch code and name in $createlibrary variable
147
    $template->param( 'createlibrary' => $createlibrary ); # Hand the library values back to the template in the createlibrary variable
136
148
137
    #store inputted parameters in variables
149
    #store inputted parameters in variables
138
    my $branchcode       = $input->param('branchcode');
150
    my $branchcode = $input->param('branchcode');
139
    $branchcode = uc($branchcode);
151
    $branchcode = uc($branchcode);
140
    my $categorycode     = $input->param('categorycode');
152
    my $categorycode = $input->param('categorycode');
141
    my $op               = $input->param('op') || 'list';
153
    my $op = $input->param('op') || 'list';
142
    my $message;
154
    my $message;
143
    my $library;
155
    my $library;
144
156
145
    #Take the text 'branchname' and store it in the @fields array
157
    #Take the text 'branchname' and store it in the @fields array
146
    my @fields = qw(
158
    my @fields = qw(
147
        branchname
159
      branchname
148
    );
160
    );
149
161
150
    $template->param('branchcode'=>$branchcode); 
162
    $template->param( 'branchcode' => $branchcode );
151
    $branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode 
163
    $branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode
152
164
153
    #Create a new library object and store the branchcode and @fields array values in this new library object
165
#Create a new library object and store the branchcode and @fields array values in this new library object
154
    my $library = Koha::Library->new(
166
    my $library = Koha::Library->new(
155
        {   branchcode => $branchcode,
167
        {
168
            branchcode => $branchcode,
156
            ( map { $_ => scalar $input->param($_) || undef } @fields )
169
            ( map { $_ => scalar $input->param($_) || undef } @fields )
157
        }
170
        }
158
    );
171
    );
159
172
160
    eval { $library->store; }; #Use the eval{} function to store the library object
173
    eval { $library->store; }; #Use the eval{} function to store the library object
161
    if($library){
174
    if ($library) {
162
       $message = 'success_on_insert';
175
        $message = 'success_on_insert';
163
    }else{
164
       $message = 'error_on_insert';
165
    }
176
    }
166
177
    else {
167
    $template->param('message' => $message);
178
        $message = 'error_on_insert';
168
179
    }
180
    $template->param( 'message' => $message );
169
181
170
#Check if the $step variable equals 2 i.e. the user has clicked to create a patron category in the create patron category screen 1
182
#Check if the $step variable equals 2 i.e. the user has clicked to create a patron category in the create patron category screen 1
171
}elsif ( $step && $step == 2 ){
183
}
172
      my $createcat = $query->param('createcat'); #Store the inputted category code and name in $createcat
184
elsif ( $step && $step == 2 ) {
173
      $template->param('createcat'=>$createcat);
185
    my $createcat = $input->param('createcat');    #Store the inputted category code and name in $createcat
174
186
    $template->param( 'createcat' => $createcat );
175
     #Initialising values
187
176
     my $searchfield   = $input->param('description') // q||;
188
    #Initialising values
177
     my $categorycode  = $input->param('categorycode');
189
    my $searchfield  = $input->param('description') // q||;
178
     my $op            = $input->param('op') // 'list';
190
    my $categorycode = $input->param('categorycode');
179
     my $message;
191
    my $op           = $input->param('op') // 'list';
180
     my $category;
192
    my $message;
181
     $template->param('categorycode' =>$categorycode);
193
    my $category;
182
194
    $template->param( 'categorycode' => $categorycode );
183
     my ( $template, $loggedinuser, $cookie ) =  C4::InstallAuth::get_template_and_user(
195
184
     {
196
    my ( $template, $loggedinuser, $cookie ) =
185
        template_name   => "/onboarding/onboardingstep2.tt",
197
      C4::InstallAuth::get_template_and_user(
186
        query           => $input,
198
        {
187
        type            => "intranet",
199
            template_name   => "/onboarding/onboardingstep2.tt",
188
        authnotrequired => 0,
200
            query           => $input,
189
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
201
            type            => "intranet",
190
        debug           => 1,
202
            authnotrequired => 0,
203
            flagsrequired =>
204
              { parameters => 'parameters_remaining_permissions' },
205
            debug => 1,
191
        }
206
        }
192
    );
207
      );
193
    
208
194
    #Once the user submits the page, this code validates the input and adds it
209
    #Once the user submits the page, this code validates the input and adds it
195
    #to the database as a new patron category 
210
    #to the database as a new patron category
196
    $categorycode = $input->param('categorycode');
211
    $categorycode = $input->param('categorycode');
197
    my $description = $input->param('description');
212
    my $description           = $input->param('description');
198
    my $overduenoticerequired = $input->param('overduenoticerequired');
213
    my $overduenoticerequired = $input->param('overduenoticerequired');
199
    my $category_type = $input->param('category_type');
214
    my $category_type         = $input->param('category_type');
200
    my $default_privacy = $input->param('default_privacy');
215
    my $default_privacy       = $input->param('default_privacy');
201
    my $enrolmentperiod = $input->param('enrolmentperiod');
216
    my $enrolmentperiod       = $input->param('enrolmentperiod');
202
    my $enrolmentperioddate = $input->param('enrolmentperioddate') || undef;
217
    my $enrolmentperioddate   = $input->param('enrolmentperioddate') || undef;
203
218
204
    #Converts the string into a date format
219
    #Converts the string into a date format
205
    if ( $enrolmentperioddate) {
220
    if ($enrolmentperioddate) {
206
         $enrolmentperioddate = output_pref(
221
        $enrolmentperioddate = output_pref(
207
                    {
222
            {
208
                    dt         => dt_from_string($enrolmentperioddate),
223
                dt         => dt_from_string($enrolmentperioddate),
209
                    dateformat => 'iso',
224
                dateformat => 'iso',
210
                    dateonly   => 1,
225
                dateonly   => 1,
211
                    }
226
            }
212
            );
227
        );
228
    }
229
230
    #Adds a new patron category to the database
231
    $category = Koha::Patron::Category->new(
232
        {
233
            categorycode          => $categorycode,
234
            description           => $description,
235
            overduenoticerequired => $overduenoticerequired,
236
            category_type         => $category_type,
237
            default_privacy       => $default_privacy,
238
            enrolmentperiod       => $enrolmentperiod,
239
            enrolmentperioddate   => $enrolmentperioddate,
213
        }
240
        }
241
    );
214
242
215
#Adds a new patron category to the database
243
    eval { $category->store; };
216
        $category = Koha::Patron::Category->new({
217
                categorycode=> $categorycode,
218
                description => $description,
219
                overduenoticerequired => $overduenoticerequired,
220
                category_type=> $category_type,
221
                default_privacy => $default_privacy,
222
                enrolmentperiod => $enrolmentperiod,
223
                enrolmentperioddate => $enrolmentperioddate,
224
        });
225
226
        eval {
227
            $category->store;
228
        };
229
244
230
#Error messages
245
    #Error messages
231
        if($category){
246
    if ($category) {
232
            $message = 'success_on_insert';
247
        $message = 'success_on_insert';
233
        }else{
248
    }
234
            $message = 'error_on_insert';
249
    else {
235
        }
250
        $message = 'error_on_insert';
251
    }
236
252
237
        $template->param('message' => $message);
253
    $template->param( 'message' => $message );
238
254
239
#Create a patron
255
    #Create a patron
240
}elsif ( $step && $step == 3 ){
256
}
241
    my $firstpassword = $input->param('password');
257
elsif ( $step && $step == 3 ) {
258
    my $firstpassword  = $input->param('password');
242
    my $secondpassword = $input->param('password2');
259
    my $secondpassword = $input->param('password2');
243
260
244
#Find all library records in the database and hand them to the template to display in the library dropdown box
261
#Find all library records in the database and hand them to the template to display in the library dropdown box
245
    my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
262
    my $libraries =
246
    $template->param(libraries   => $libraries,
263
      Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
247
              group_types => [
264
    $template->param(
248
                {   categorytype => 'searchdomain',
265
        libraries   => $libraries,
249
                    categories   => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ],
266
        group_types => [
250
                },
267
            {
251
                {   categorytype => 'properties',
268
                categorytype => 'searchdomain',
252
                         categories   => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ],
269
                categories   => [
253
                },
270
                    Koha::LibraryCategories->search(
254
              ]
271
                        { categorytype => 'searchdomain' }
272
                    )
273
                ],
274
            },
275
            {
276
                categorytype => 'properties',
277
                categories   => [
278
                    Koha::LibraryCategories->search(
279
                        { categorytype => 'properties' }
280
                    )
281
                ],
282
            },
283
        ]
255
    );
284
    );
256
285
257
#Find all patron categories in the database and hand them to the template to display in the patron category dropdown box
286
#Find all patron categories in the database and hand them to the template to display in the patron category dropdown box
258
    my $categories= Koha::Patron::Categories->search();
287
    my $categories = Koha::Patron::Categories->search();
259
    $template->param(
288
    $template->param( categories => $categories, );
260
            categories => $categories,
261
    );
262
289
263
#Incrementing the highest existing patron cardnumber to prevent duplicate cardnumber entry
290
#Incrementing the highest existing patron cardnumber to prevent duplicate cardnumber entry
264
    my $exisiting_cardnumber = my $sth_search = $dbh->prepare("SELECT MAX(cardnumber) FROM borrowers");
291
    my $exisiting_cardnumber = my $sth_search =
292
      $dbh->prepare("SELECT MAX(cardnumber) FROM borrowers");
265
    my $new_cardnumber = $exisiting_cardnumber + 1;
293
    my $new_cardnumber = $exisiting_cardnumber + 1;
266
    warn $new_cardnumber;
294
    warn $new_cardnumber;
267
    $template->param("newcardnumber" => $new_cardnumber);
295
    $template->param( "newcardnumber" => $new_cardnumber );
268
269
270
296
271
    my $op = $input->param('op') // 'list';
297
    my $op = $input->param('op') // 'list';
272
    my $minpw = C4::Context->preference("minPasswordLength");
298
    my $minpw = C4::Context->preference("minPasswordLength");
273
    $template->param("minPasswordLength" => $minpw);
299
    $template->param( "minPasswordLength" => $minpw );
274
275
    my @messages;
300
    my @messages;
276
    my @errors;
301
    my @errors;
277
    my $nok = $input->param('nok');
302
    my $nok            = $input->param('nok');
278
    my $firstpassword = $input->param('password');
303
    my $firstpassword  = $input->param('password');
279
    my $secondpassword = $input->param('password2');
304
    my $secondpassword = $input->param('password2');
280
    my $cardnumber= $input->param('cardnumber');
305
    my $cardnumber     = $input->param('cardnumber');
281
    my $borrowernumber= $input->param('borrowernumber');
306
    my $borrowernumber = $input->param('borrowernumber');
282
    my $userid=$input->param('userid');
307
    my $userid         = $input->param('userid');
283
308
284
#If the entered cardnumber causes an error hand this error to the @errors array
309
 #If the entered cardnumber causes an error hand this error to the @errors array
285
    if(my $error_code = checkcardnumber($cardnumber, $borrowernumber)){
310
    if ( my $error_code = checkcardnumber( $cardnumber, $borrowernumber ) ) {
286
            push @errors, $error_code == 1
311
        push @errors,
287
                ? 'ERROR_cardnumber_already_exists'
312
            $error_code == 1 ? 'ERROR_cardnumber_already_exists'
288
                :$error_code == 2
313
          : $error_code == 2 ? 'ERROR_cardnumber_length'
289
                    ? 'ERROR_cardnumber_length'
314
          :                    ();
290
                    :()
291
    }
315
    }
292
316
293
#If the entered password causes an error hand this error to the @errors array
317
   #If the entered password causes an error hand this error to the @errors array
294
  push @errors, "ERROR_password_mismatch" if $firstpassword ne $secondpassword;
318
    push @errors, "ERROR_password_mismatch"
295
  push @errors, "ERROR_short_password" if ($firstpassword && $minpw && $firstpassword ne '****' && (length($firstpassword) < $minpw));
319
      if $firstpassword ne $secondpassword;
320
    push @errors, "ERROR_short_password"
321
      if ( $firstpassword
322
        && $minpw
323
        && $firstpassword ne '****'
324
        && ( length($firstpassword) < $minpw ) );
296
325
297
326
    #Passing errors to template
298
#Passing errors to template
327
    $nok = $nok || scalar(@errors);
299
   $nok = $nok || scalar(@errors);
300
328
301
#If errors have been generated from the users inputted cardnumber or password then display the error and do not insert the patron into the borrowers table
329
#If errors have been generated from the users inputted cardnumber or password then display the error and do not insert the patron into the borrowers table
302
   if($nok){
330
    if ($nok) {
303
      foreach my $error (@errors){
331
        foreach my $error (@errors) {
304
          if ($error eq 'ERROR_password_mismatch'){
332
            if ( $error eq 'ERROR_password_mismatch' ) {
305
              $template->param(errorpasswordmismatch => 1);
333
                $template->param( errorpasswordmismatch => 1 );
306
           }
334
            }
307
           if ($error eq 'ERROR_login_exist'){
335
            if ( $error eq 'ERROR_login_exist' ) {
308
                $template->param(errorloginexists =>1);
336
                $template->param( errorloginexists => 1 );
309
           }
337
            }
310
           if ($error eq 'ERROR_cardnumber_already_exists'){
338
            if ( $error eq 'ERROR_cardnumber_already_exists' ) {
311
                $template->param(errorcardnumberexists => 1);
339
                $template->param( errorcardnumberexists => 1 );
312
           }
340
            }
313
           if ($error eq 'ERROR_cardnumber_length'){
341
            if ( $error eq 'ERROR_cardnumber_length' ) {
314
                $template->param(errorcardnumberlength => 1);
342
                $template->param( errorcardnumberlength => 1 );
315
           }
343
            }
316
           if ($error eq 'ERROR_short_password'){
344
            if ( $error eq 'ERROR_short_password' ) {
317
                $template->param(errorshortpassword => 1);
345
                $template->param( errorshortpassword => 1 );
318
           }
346
            }
319
       }
347
        }
320
        $template->param('nok' => 1);
348
        $template->param( 'nok' => 1 );
321
349
322
#Else if no errors have been caused by the users inputted card number or password then insert the patron into the borrowers table
350
#Else if no errors have been caused by the users inputted card number or password then insert the patron into the borrowers table
323
   }else{
351
    }
324
    my ($template, $loggedinuser, $cookie)= C4::InstallAuth::get_template_and_user({
352
    else {
325
                template_name => "/onboarding/onboardingstep3.tt",
353
        my ( $template, $loggedinuser, $cookie ) =
326
                query => $input,
354
          C4::InstallAuth::get_template_and_user(
327
                type => "intranet",
355
            {
356
                template_name   => "/onboarding/onboardingstep3.tt",
357
                query           => $input,
358
                type            => "intranet",
328
                authnotrequired => 0,
359
                authnotrequired => 0,
329
                flagsrequired => {borrowers => 1},
360
                flagsrequired   => { borrowers => 1 },
330
                debug => 1,
361
                debug           => 1,
331
    });
362
            }
332
363
          );
333
    if($op eq 'add_validate'){
364
334
         my %newdata;
365
        if ( $op eq 'add_validate' ) {
335
366
            my %newdata;
336
#Store the template form values in the newdata hash      
367
337
         $newdata{borrowernumber} = $input->param('borrowernumber');       
368
            #Store the template form values in the newdata hash
338
         $newdata{surname}  = $input->param('surname');
369
            $newdata{borrowernumber} = $input->param('borrowernumber');
339
         $newdata{firstname}  = $input->param('firstname');
370
            $newdata{surname}        = $input->param('surname');
340
         $newdata{cardnumber} = $input->param('cardnumber');
371
            $newdata{firstname}      = $input->param('firstname');
341
         $newdata{branchcode} = $input->param('libraries');
372
            $newdata{cardnumber}     = $input->param('cardnumber');
342
         $newdata{categorycode} = $input->param('categorycode_entry');
373
            $newdata{branchcode}     = $input->param('libraries');
343
         $newdata{userid} = $input->param('userid');
374
            $newdata{categorycode}   = $input->param('categorycode_entry');
344
         $newdata{password} = $input->param('password');
375
            $newdata{userid}         = $input->param('userid');
345
         $newdata{password2} = $input->param('password2');
376
            $newdata{password}       = $input->param('password');
346
         $newdata{dateexpiry} = '12/10/2016';
377
            $newdata{password2}      = $input->param('password2');
347
         $newdata{privacy} = "default";
378
            $newdata{dateexpiry}     = '12/10/2016';
348
379
            $newdata{privacy}        = "default";
349
380
350
#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
381
#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
351
        my $borrowernumber = &AddMember(%newdata);
382
            my $borrowernumber = &AddMember(%newdata);
352
383
353
#Create a hash named member2 and fill it with the borrowernumber of the borrower that has just been created
384
#Create a hash named member2 and fill it with the borrowernumber of the borrower that has just been created
354
        my %member2;
385
            my %member2;
355
        $member2{'borrowernumber'}=$borrowernumber;
386
            $member2{'borrowernumber'} = $borrowernumber;
356
387
357
#Perform data validation on the flag that has been handed to onboarding.pl by the template
388
#Perform data validation on the flag that has been handed to onboarding.pl by the template
358
        my $flag = $input->param('flag');
389
            my $flag = $input->param('flag');
359
        if ($input->param('newflags')) {
390
            if ( $input->param('newflags') ) {
360
             my $dbh=C4::Context->dbh();
391
                my $dbh              = C4::Context->dbh();
361
             my @perms = $input->multi_param('flag');
392
                my @perms            = $input->multi_param('flag');
362
             my %all_module_perms = ();
393
                my %all_module_perms = ();
363
             my %sub_perms = ();
394
                my %sub_perms        = ();
364
             foreach my $perm (@perms) {
395
                foreach my $perm (@perms) {
365
                  if ($perm !~ /:/) {
396
                    if ( $perm !~ /:/ ) {
366
                       $all_module_perms{$perm} = 1;
397
                        $all_module_perms{$perm} = 1;
367
                   } else {
398
                    }
368
                        my ($module, $sub_perm) = split /:/, $perm, 2;
399
                    else {
400
                        my ( $module, $sub_perm ) = split /:/, $perm, 2;
369
                        push @{ $sub_perms{$module} }, $sub_perm;
401
                        push @{ $sub_perms{$module} }, $sub_perm;
370
                   }
402
                    }
371
             }
403
                }
372
404
373
             # construct flags
405
                # construct flags
374
             my $module_flags = 0;
406
                my $module_flags = 0;
375
             my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
407
                my $sth =
376
             $sth->execute();
408
                  $dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
377
             while (my ($bit, $flag) = $sth->fetchrow_array) {
409
                $sth->execute();
378
                  if (exists $all_module_perms{$flag}) {
410
                while ( my ( $bit, $flag ) = $sth->fetchrow_array ) {
379
                     $module_flags += 2**$bit;
411
                    if ( exists $all_module_perms{$flag} ) {
380
                  }
412
                        $module_flags += 2**$bit;
381
             }
413
                    }
414
                }
382
415
383
#Set the superlibrarian permission of the newly created patron to superlibrarian
416
#Set the superlibrarian permission of the newly created patron to superlibrarian
384
             $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
417
                $sth = $dbh->prepare(
385
             $sth->execute($module_flags, $borrowernumber);
418
                    "UPDATE borrowers SET flags=? WHERE borrowernumber=?");
386
419
                $sth->execute( $module_flags, $borrowernumber );
387
420
388
             #Error handling checking if the patron was created successfully
421
                #Error handling checking if the patron was created successfully
389
             if(!$borrowernumber){
422
                if ( !$borrowernumber ) {
390
                  push @messages, {type=> 'error', code => 'error_on_insert'};
423
                    push @messages,
391
             }else{
424
                      { type => 'error', code => 'error_on_insert' };
392
                  push @messages, {type=> 'message', code => 'success_on_insert'};
425
                }
393
             }
426
                else {
394
          }
427
                    push @messages,
428
                      { type => 'message', code => 'success_on_insert' };
429
                }
430
            }
395
        }
431
        }
396
    }
432
    }
397
433
}
398
 }elsif ( $step && $step == 4){
434
elsif ( $step && $step == 4 ) {
399
    my $createitemtype = $input->param('createitemtype');
435
    my $createitemtype = $input->param('createitemtype');
400
    $template->param('createitemtype'=> $createitemtype );
436
    $template->param( 'createitemtype' => $createitemtype );
401
437
402
438
    my ( $template, $borrowernumber, $cookie ) =
403
    my( $template, $borrowernumber, $cookie) = C4::InstallAuth::get_template_and_user(
439
      C4::InstallAuth::get_template_and_user(
404
            {   template_name   => "/onboarding/onboardingstep4.tt",
440
        {
405
                query           => $input,
441
            template_name   => "/onboarding/onboardingstep4.tt",
406
                type            => "intranet",
442
            query           => $input,
407
                authnotrequired => 0,
443
            type            => "intranet",
408
                flagsrequired   => { parameters => 'parameters_remaining_permissions'},
444
            authnotrequired => 0,
409
                debug           => 1,
445
            flagsrequired =>
410
            }
446
              { parameters => 'parameters_remaining_permissions' },
411
    );
447
            debug => 1,
448
        }
449
      );
412
450
413
    if($op eq 'add_validate'){
451
    if ( $op eq 'add_validate' ) {
414
        my $description = $input->param('description');
452
        my $description   = $input->param('description');
415
        my $itemtype_code = $input->param('itemtype');
453
        my $itemtype_code = $input->param('itemtype');
416
        $itemtype_code = uc($itemtype_code);
454
        $itemtype_code = uc($itemtype_code);
417
        #Create a new itemtype object using the user inputted itemtype and description
455
418
        my $itemtype= Koha::ItemType->new(
456
  #Create a new itemtype object using the user inputted itemtype and description
419
            { itemtype    => $itemtype_code,
457
        my $itemtype = Koha::ItemType->new(
420
              description => $description,
458
            {
459
                itemtype    => $itemtype_code,
460
                description => $description,
421
            }
461
            }
422
        );
462
        );
423
463
        eval { $itemtype->store; };
424
        eval{ $itemtype->store; };
425
426
        my $message;
464
        my $message;
427
465
428
#Fill the $message variable with an error if the item type object was not successfully created and inserted into the itemtypes table
466
#Fill the $message variable with an error if the item type object was not successfully created and inserted into the itemtypes table
429
        if($itemtype){
467
        if ($itemtype) {
430
            $message = 'success_on_insert';
468
            $message = 'success_on_insert';
431
        }else{
469
        }
470
        else {
432
            $message = 'error_on_insert';
471
            $message = 'error_on_insert';
433
        }
472
        }
434
473
        $template->param( 'message' => $message );
435
        $template->param('message' => $message);
436
    }
474
    }
437
}elsif ( $step && $step == 5){
475
}
476
elsif ( $step && $step == 5 ) {
438
477
439
    #Find all the existing categories to display in a dropdown box in the template
478
  #Find all the existing categories to display in a dropdown box in the template
440
    my $categories;
479
    my $categories;
441
    $categories= Koha::Patron::Categories->search();
480
    $categories = Koha::Patron::Categories->search();
442
    $template->param(
481
    $template->param( categories => $categories, );
443
        categories => $categories,
444
    );
445
482
446
    #Find all the exisiting item types to display in a dropdown box in the template
483
 #Find all the exisiting item types to display in a dropdown box in the template
447
    my $itemtypes;
484
    my $itemtypes;
448
    $itemtypes= Koha::ItemTypes->search();
485
    $itemtypes = Koha::ItemTypes->search();
449
    $template->param(
486
    $template->param( itemtypes => $itemtypes, );
450
        itemtypes => $itemtypes,
451
    );
452
487
453
    #Find all the exisiting libraries to display in a dropdown box in the template
488
  #Find all the exisiting libraries to display in a dropdown box in the template
454
    my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
489
    my $libraries =
455
    $template->param(libraries   => $libraries,
490
      Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
456
                     group_types => [
491
    $template->param(
457
                {   categorytype => 'searchdomain',
492
        libraries   => $libraries,
458
                    categories   => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ],
493
        group_types => [
459
                },
494
            {
460
                {   categorytype => 'properties',
495
                categorytype => 'searchdomain',
461
                    categories   => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ],
496
                categories   => [
462
                },
497
                    Koha::LibraryCategories->search(
463
                ]
498
                        { categorytype => 'searchdomain' }
499
                    )
500
                ],
501
            },
502
            {
503
                categorytype => 'properties',
504
                categories   => [
505
                    Koha::LibraryCategories->search(
506
                        { categorytype => 'properties' }
507
                    )
508
                ],
509
            },
510
        ]
464
    );
511
    );
465
512
466
    my $input = CGI->new;
513
    my $input = CGI->new;
467
    my $dbh = C4::Context->dbh;
514
    my $dbh   = C4::Context->dbh;
468
515
469
    my ($template, $loggedinuser, $cookie) = C4::InstallAuth::get_template_and_user({template_name => "/onboarding/onboardingstep5.tt",
516
    my ( $template, $loggedinuser, $cookie ) =
470
                query => $input,
517
      C4::InstallAuth::get_template_and_user(
471
                type => "intranet",
518
        {
472
                authnotrequired => 0,
519
            template_name   => "/onboarding/onboardingstep5.tt",
473
                flagsrequired => {parameters => 'manage_circ_rules'},
520
            query           => $input,
474
                debug => 1,
521
            type            => "intranet",
475
    });
522
            authnotrequired => 0,
523
            flagsrequired   => { parameters => 'manage_circ_rules' },
524
            debug           => 1,
525
        }
526
      );
476
527
477
#If no libraries exist then set the $branch value to *
528
    #If no libraries exist then set the $branch value to *
478
    my $branch = $input->param('branch');
529
    my $branch = $input->param('branch');
479
    unless ( $branch ) {
530
    unless ($branch) {
480
          if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) {
531
        if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) {
481
                $branch = Koha::Libraries->search->count() == 1 ? undef : C4::Context::mybranch();
532
            $branch =
482
           }
533
              Koha::Libraries->search->count() == 1
483
           else {
534
              ? undef
484
                $branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*';
535
              : C4::Context::mybranch();
485
           }
536
        }
537
        else {
538
            $branch =
539
              C4::Context::only_my_library()
540
              ? ( C4::Context::mybranch() || '*' )
541
              : '*';
542
        }
486
    }
543
    }
487
    $branch = '*' if $branch eq 'NO_LIBRARY_SET';
544
    $branch = '*' if $branch eq 'NO_LIBRARY_SET';
488
    my $op = $input->param('op') || q{};
545
    my $op = $input->param('op') || q{};
489
546
490
    if($op eq 'add_validate'){
547
    if ( $op eq 'add_validate' ) {
491
        my $type = $input->param('type');
548
        my $type            = $input->param('type');
492
        my $br = $input->param('branch');
549
        my $br              = $input->param('branch');
493
        my $bor = $input->param('categorycode');
550
        my $bor             = $input->param('categorycode');
494
        my $itemtype = $input->param('itemtype');
551
        my $itemtype        = $input->param('itemtype');
495
        my $maxissueqty = $input->param('maxissueqty');
552
        my $maxissueqty     = $input->param('maxissueqty');
496
        my $issuelength = $input->param('issuelength');
553
        my $issuelength     = $input->param('issuelength');
497
        my $lengthunit = $input->param('lengthunit');
554
        my $lengthunit      = $input->param('lengthunit');
498
        my $renewalsallowed = $input->param('renewalsallowed');
555
        my $renewalsallowed = $input->param('renewalsallowed');
499
        my $renewalperiod = $input->param('renewalperiod');
556
        my $renewalperiod   = $input->param('renewalperiod');
500
        my $onshelfholds = $input->param('onshelfholds') || 0;
557
        my $onshelfholds    = $input->param('onshelfholds') || 0;
501
        $maxissueqty =~ s/\s//g;
558
        $maxissueqty =~ s/\s//g;
502
        $maxissueqty = undef if $maxissueqty !~ /^\d+/;
559
        $maxissueqty = undef if $maxissueqty !~ /^\d+/;
503
        $issuelength = $issuelength eq q{} ? undef : $issuelength;
560
        $issuelength = $issuelength eq q{} ? undef : $issuelength;
504
561
505
        my $params ={
562
        my $params = {
506
            branchcode      => $br,
563
            branchcode      => $br,
507
            categorycode    => $bor,
564
            categorycode    => $bor,
508
            itemtype        => $itemtype,
565
            itemtype        => $itemtype,
Lines 514-593 if ( $start && $start eq 'Start setting up my Koha' ){ Link Here
514
            onshelfholds    => $onshelfholds,
571
            onshelfholds    => $onshelfholds,
515
        };
572
        };
516
573
517
         my @messages;
574
        my @messages;
518
575
519
#New code from smart-rules.tt starts here. Needs to be added to library
576
#New code from smart-rules.tt starts here. Needs to be added to library
520
#Allows for the 'All' option to work when selecting all libraries for a circulation rule to apply to.
577
#Allows for the 'All' option to work when selecting all libraries for a circulation rule to apply to.
521
 if ($branch eq "*") {
578
        if ( $branch eq "*" ) {
522
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
579
            my $sth_search = $dbh->prepare(
523
                                        FROM default_circ_rules");
580
                "SELECT count(*) AS total
524
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
581
                                        FROM default_circ_rules"
582
            );
583
            my $sth_insert = $dbh->prepare(
584
                "INSERT INTO default_circ_rules
525
                                        (maxissueqty, onshelfholds)
585
                                        (maxissueqty, onshelfholds)
526
                                        VALUES (?, ?)");
586
                                        VALUES (?, ?)"
527
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
587
            );
528
                                        SET maxissueqty = ?, onshelfholds = ?");
588
            my $sth_update = $dbh->prepare(
529
589
                "UPDATE default_circ_rules
530
        $sth_search->execute();
590
                                        SET maxissueqty = ?, onshelfholds = ?"
531
        my $res = $sth_search->fetchrow_hashref();
591
            );
532
        if ($res->{total}) {
533
            $sth_update->execute($maxissueqty, $onshelfholds);
534
        } else {
535
            $sth_insert->execute($maxissueqty, $onshelfholds);
536
        }
537
    }
538
592
593
            $sth_search->execute();
594
            my $res = $sth_search->fetchrow_hashref();
595
            if ( $res->{total} ) {
596
                $sth_update->execute( $maxissueqty, $onshelfholds );
597
            }
598
            else {
599
                $sth_insert->execute( $maxissueqty, $onshelfholds );
600
            }
601
        }
539
602
540
#Allows for the 'All' option to work when selecting all patron categories for a circulation rule to apply to.
603
#Allows for the 'All' option to work when selecting all patron categories for a circulation rule to apply to.
541
        if ($bor eq "*") {
604
        if ( $bor eq "*" ) {
542
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
605
            my $sth_search = $dbh->prepare(
543
                                            FROM default_circ_rules");
606
                "SELECT count(*) AS total
544
            my $sth_insert = $dbh->prepare(q|
607
                                            FROM default_circ_rules"
608
            );
609
            my $sth_insert = $dbh->prepare(
610
                q|
545
                INSERT INTO default_circ_rules
611
                INSERT INTO default_circ_rules
546
                    (maxissueqty)
612
                    (maxissueqty)
547
                    VALUES (?)
613
                    VALUES (?)
548
            |);
614
            |
549
            my $sth_update = $dbh->prepare(q|
615
            );
616
            my $sth_update = $dbh->prepare(
617
                q|
550
                UPDATE default_circ_rules
618
                UPDATE default_circ_rules
551
                SET maxissueqty = ?
619
                SET maxissueqty = ?
552
            |);
620
            |
621
            );
553
622
554
            $sth_search->execute();
623
            $sth_search->execute();
555
            my $res = $sth_search->fetchrow_hashref();
624
            my $res = $sth_search->fetchrow_hashref();
556
            if ($res->{total}) {
625
            if ( $res->{total} ) {
557
                $sth_update->execute($maxissueqty);
626
                $sth_update->execute($maxissueqty);
558
            } else {
627
            }
628
            else {
559
                $sth_insert->execute($maxissueqty);
629
                $sth_insert->execute($maxissueqty);
560
            }
630
            }
561
        }
631
        }
632
562
#Allows for the 'All' option to work when selecting all itemtypes for a circulation rule to apply to
633
#Allows for the 'All' option to work when selecting all itemtypes for a circulation rule to apply to
563
        if ($itemtype eq "*") {
634
        if ( $itemtype eq "*" ) {
564
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
635
            my $sth_search = $dbh->prepare(
636
                "SELECT count(*) AS total
565
                                        FROM default_branch_circ_rules
637
                                        FROM default_branch_circ_rules
566
                                        WHERE branchcode = ?");
638
                                        WHERE branchcode = ?"
567
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
639
            );
640
            my $sth_insert = $dbh->prepare(
641
                "INSERT INTO default_branch_circ_rules
568
                                        (branchcode, onshelfholds)
642
                                        (branchcode, onshelfholds)
569
                                        VALUES (?, ?)");
643
                                        VALUES (?, ?)"
570
            my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
644
            );
645
            my $sth_update = $dbh->prepare(
646
                "UPDATE default_branch_circ_rules
571
                                        SET onshelfholds = ?
647
                                        SET onshelfholds = ?
572
                                        WHERE branchcode = ?");
648
                                        WHERE branchcode = ?"
649
            );
573
            $sth_search->execute($branch);
650
            $sth_search->execute($branch);
574
            my $res = $sth_search->fetchrow_hashref();
651
            my $res = $sth_search->fetchrow_hashref();
575
            if ($res->{total}) {
652
            if ( $res->{total} ) {
576
                $sth_update->execute($onshelfholds, $branch);
653
                $sth_update->execute( $onshelfholds, $branch );
577
            } else {
654
            }
578
            $sth_insert->execute($branch, $onshelfholds);
655
            else {
656
                $sth_insert->execute( $branch, $onshelfholds );
579
            }
657
            }
580
        }
658
        }
581
#End new code
582
659
583
       my $issuingrule = Koha::IssuingRules->find({categorycode => $bor, itemtype => $itemtype, branchcode => $br });
660
        #End new code
584
       if($issuingrule){
585
           $issuingrule->set($params)->store();
586
           push @messages, {type=> 'error', code => 'error_on_insert'};#Stops crash of the onboarding tool if someone makes a circulation rule with the same item type, library and patron categroy as an exisiting circulation rule.
587
661
588
       }else{
662
        my $issuingrule = Koha::IssuingRules->find(
589
           Koha::IssuingRule->new()->set($params)->store();
663
            { categorycode => $bor, itemtype => $itemtype, branchcode => $br }
590
       }
664
        );
665
        if ($issuingrule) {
666
            $issuingrule->set($params)->store();
667
            push @messages,
668
              { type => 'error', code => 'error_on_insert'
669
              }; #Stops crash of the onboarding tool if someone makes a circulation rule with the same item type, library and patron categroy as an exisiting circulation rule.
670
671
        }
672
        else {
673
            Koha::IssuingRule->new()->set($params)->store();
674
        }
591
    }
675
    }
592
}
676
}
593
677
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep1.tt (-1 lines)
Lines 43-49 Link Here
43
            </form>
43
            </form>
44
44
45
        [%ELSE %]
45
        [%ELSE %]
46
            <!--Implement if statement to determine if library was succesfully created here....-->
47
            <form name="retrylibrary" method="post" action="onboarding.pl">
46
            <form name="retrylibrary" method="post" action="onboarding.pl">
48
                <input type="hidden" name="step" value="1"/>
47
                <input type="hidden" name="step" value="1"/>
49
                <h1 align="left">Failed </h1>
48
                <h1 align="left">Failed </h1>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep3.tt (-10 / +4 lines)
Lines 2-15 Link Here
2
[% USE Koha %]
2
[% USE Koha %]
3
[% USE KohaDates %]
3
[% USE KohaDates %]
4
[% USE Price %]
4
[% USE Price %]
5
<!--[% USE Branches %]-->
6
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
7
[% IF ( finish ) %]<meta http-equiv="refresh" content="10; url=/cgi-bin/koha/mainpage.pl">[% END%]
6
[% IF ( finish ) %]<meta http-equiv="refresh" content="10; url=/cgi-bin/koha/mainpage.pl">[% END%]
8
[% INCLUDE 'installer-doc-head-close.inc' %]
7
[% INCLUDE 'installer-doc-head-close.inc' %]
9
[% INCLUDE 'calendar.inc' %]
8
[% INCLUDE 'calendar.inc' %]
10
[% INCLUDE 'datatables.inc' %]
9
[% INCLUDE 'datatables.inc' %]
11
10
12
13
<head>
11
<head>
14
<title>Create Patron</title>
12
<title>Create Patron</title>
15
13
Lines 124-135 $(document).ready(function(){ Link Here
124
            <fieldset class="rows">
122
            <fieldset class="rows">
125
                 <input type="hidden" name="step" value="3"/>
123
                 <input type="hidden" name="step" value="3"/>
126
                 <input type="hidden" name="op" value="add_validate" />
124
                 <input type="hidden" name="op" value="add_validate" />
127
                     <legend id="library_management_lgd">Library Management</legend>
125
                    <legend id="library_management_lgd">Library Management</legend>
128
                     <p>
126
                    <ol>
129
                        Now we will create a patron with superlibrarian permissions. Login with this to access Koha as a staff member will all permissions.
130
                     </p>
131
132
                     <ol>
133
                    <h3>Patron Identity</h3>
127
                    <h3>Patron Identity</h3>
134
                        <li>
128
                        <li>
135
                            <label for="surname" class="required">Surname: </label>
129
                            <label for="surname" class="required">Surname: </label>
Lines 191-202 $(document).ready(function(){ Link Here
191
                        </li>
185
                        </li>
192
                        <li>
186
                        <li>
193
                            <label for="passwordlabel" class="required">Password: </label>
187
                            <label for="passwordlabel" class="required">Password: </label>
194
                            <input type="password" name="password" pattern="[A-Za-z1-9 ]+" title="Please only enter letters or numbers into this password field" id="password" size="20" value="[% member.password |html %]" class="required" required="required">
188
                            <input type="password" name="password" id="password" size="20" value="[% member.password |html %]" class="required" required="required">
195
                            <span class="required">Required</span>
189
                            <span class="required">Required</span>
196
                        </li>
190
                        </li>
197
                        <li>
191
                        <li>
198
                            <label for="password2" class="required">Confirm password: </label>
192
                            <label for="password2" class="required">Confirm password: </label>
199
                            <input type="password" id="password2" pattern="[A-Za-z1-9 ]+" title="Please only enter letters or numbers into this password field" name="password2" size="20" value="" class="required" required="required">
193
                            <input type="password" id="password2" name="password2" size="20" value="" class="required" required="required">
200
                            <span class="required">Required</span>
194
                            <span class="required">Required</span>
201
                        </li>
195
                        </li>
202
                    </ol>
196
                    </ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/onboarding/onboardingstep4.tt (-1 / +4 lines)
Lines 40-46 Link Here
40
                <div>
40
                <div>
41
                    <p> Success: New item type created!</p>
41
                    <p> Success: New item type created!</p>
42
                    <p> To create another item type later and for more setttings <br>
42
                    <p> To create another item type later and for more setttings <br>
43
                    go to More->Administration->Item types
43
                    go to: <br><br>
44
                    More->Administration->Item types <br>
45
                    or<br>
46
                    Administration->Item types
44
                </div>
47
                </div>
45
                     Next up:
48
                     Next up:
46
                    <input type="submit" value="Add a circulation rule"/>
49
                    <input type="submit" value="Add a circulation rule"/>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/summary.tt (-3 / +6 lines)
Lines 16-26 Link Here
16
            <fieldset style="font-size:120%">
16
            <fieldset style="font-size:120%">
17
            <h2>Library</h2>
17
            <h2>Library</h2>
18
            <p> To add another library and for more settings, go to </br>
18
            <p> To add another library and for more settings, go to </br>
19
            More > Administration > Libraries and Groups </p>
19
            More > Administration > Libraries and groups </p> OR<br>
20
            Administration->Libraries and groups
20
21
21
            <h2>Patron Category</h2>
22
            <h2>Patron Category</h2>
22
            <p>To add another patron category and for more settings, go to</br>
23
            <p>To add another patron category and for more settings, go to</br>
23
            More > Administration > Patrons and Circulation > Patron Categories</p>
24
            More > Administration > Patron Categories</p> OR <br>
25
            Administration->Patron categories
24
26
25
            <h2>Patron</h2>
27
            <h2>Patron</h2>
26
            <p>To create another patron, go to Patrons > New Patron. To set the </br>
28
            <p>To create another patron, go to Patrons > New Patron. To set the </br>
Lines 28-34 Link Here
28
30
29
            <h2>Item Type</h2>
31
            <h2>Item Type</h2>
30
            <p>To create another item type and for more settings, go to</br>
32
            <p>To create another item type and for more settings, go to</br>
31
            More > Administration > Item types </p>
33
            More > Administration > Item types </p> OR <br>
34
            Administration->Item types
32
35
33
            <h2>Circulation Rule</h2>
36
            <h2>Circulation Rule</h2>
34
            <p>To create another circulation rule, go to </br>
37
            <p>To create another circulation rule, go to </br>
(-)a/summary.pl (-19 / +2 lines)
Lines 21-46 Link Here
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
22
23
use Modern::Perl;
23
use Modern::Perl;
24
25
use CGI qw ( -utf8 );
26
use List::MoreUtils qw/ any /;
27
use LWP::Simple;
28
use XML::Simple;
29
use Config;
30
31
use C4::Output;
32
use C4::Auth;
24
use C4::Auth;
25
use C4::Output;
33
use C4::Context;
26
use C4::Context;
34
use C4::Installer;
27
use C4::Koha;
35
36
use Koha;
37
use Koha::Acquisition::Currencies;
38
use Koha::Patrons;
39
use Koha::Caches;
40
use Koha::Config::SysPrefs;
41
use C4::Members::Statistics;
42
43
#use Smart::Comments '####';
44
28
45
my $query = new CGI;
29
my $query = new CGI;
46
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47
- 

Return to bug 17855