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

(-)a/C4/SMSNumber/Fr.pm (+124 lines)
Line 0 Link Here
1
package C4::SMSNumber::Fr;
2
3
# Copyright 2017 Biblibre
4
#
5
# This file is part of Koha.
6
#
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
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
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>.
19
20
use Modern::Perl;
21
22
sub check {
23
    my ($package, $number, $option) = @_;
24
warn "Number: $number";
25
26
    if ($option eq '+33') {
27
        return _check33($number);
28
    }
29
30
    if ($option eq '0033') {
31
        return _check0033($number);
32
    }
33
34
    if ( $number =~ /^0[6-7]\d{8}$/ ) {
35
        return 1;
36
    }
37
38
    return 0;
39
}
40
41
sub _check33 {
42
    my ($number) = @_;
43
44
    if ( $number =~ /^\+33[6-7]\d{8}$/ ) {
45
        return 1;
46
    }
47
48
    return 0;
49
}
50
51
sub _check0033 {
52
    my ($number) = @_;
53
54
    if ( $number =~ /^0033[6-7]\d{8}$/ ) {
55
        return 1;
56
    }
57
58
    return 0;
59
}
60
61
sub transform {
62
    my ($package, $number, $option) = @_;
63
64
    if ($option eq '+33') {
65
        return _transform33($number);
66
    }
67
68
    if ($option eq '0033') {
69
        return _transform0033($number);
70
    }
71
72
    if ( $number =~ /^\+33\s*/ ) {
73
        $number =~ s/^\+33\s*/0/;
74
    }
75
76
    if ( $number =~ /^0*33\s*/ ) {
77
        $number =~ s/^0*33\s*/0/;
78
    }
79
80
    if ( $number =~ /^(0[6-7])[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})/ ) {
81
        return "$1$2$3$4$5";
82
    }
83
84
    return $number;
85
}
86
87
sub _transform33 {
88
    my ($number, $option) = @_;
89
90
    if ( $number =~ /^0033\s*/ ) {
91
        $number =~ s/^0033\s*/\+33/;
92
    }
93
94
    if ( $number =~ /^0([6-7])/ ) {
95
        $number =~ s/^0([6-7])/\+33$1/;
96
    }
97
98
    if ( $number =~ /^\+33[\-\s\.]*([6-7])[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})/ ) {
99
        return "+33$1$2$3$4$5";
100
    }
101
102
    return $number;
103
}
104
105
sub _transform0033 {
106
    my ($number, $option) = @_;
107
108
    if ( $number =~ /^\+33\s*/ ) {
109
        $number =~ s/^\+33\s*/0033/;
110
    }
111
112
    if ( $number =~ /^0([6-7])/ ) {
113
        $number =~ s/^0([6-7])/0033$1/;
114
    }
115
116
    if ( $number =~ /^0033[\-\s\.]*([6-7])[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})[\-\s\.]*(\d{2})/ ) {
117
        return "0033$1$2$3$4$5";
118
    }
119
120
    return $number;
121
}
122
123
124
1;
(-)a/misc/check_smsalertnumber.pl (-1 / +130 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2017 Biblibre
6
#
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
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
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>.
19
20
use Modern::Perl;
21
22
use Pod::Usage;
23
use Module::Load;
24
use Getopt::Long;
25
26
use Koha::Patrons;
27
28
my ( $help, $area, $confirm, $list_area );
29
my $area_option = '';
30
31
GetOptions(
32
    'h|help'                 => \$help,
33
    'a|area=s'               => \$area,
34
    'c|confirm'              => \$confirm,
35
    'o|option=s'             => \$area_option,
36
    'l|list-area'            => \$list_area
37
) || pod2usage(1);
38
39
if ($help) {
40
    pod2usage(1);
41
}
42
43
if ($list_area) {
44
    print "    - Fr: Checks french mobile number. options: '+33', '0033' \n";
45
46
    exit;
47
}
48
49
my $module = "C4::SMSNumber::" . ucfirst($area);
50
load $module, qw/check/;
51
52
my $patrons = Koha::Patrons->search({});
53
while ( my $patron = $patrons->next() ) {
54
    my $number = $patron->smsalertnumber();
55
    my $id = $patron->id();
56
57
    next unless $number;
58
59
    my $valid = $module->check($number, $area_option);
60
    next if $valid;
61
62
    print "Patron n° $id has an invalid phone number for area $area ($number).\n";
63
64
    my $replacement = $module->transform($number, $area_option);
65
    if ($replacement ne $number) {
66
        print "$number  => $replacement\n\n";
67
        $patron->set({ smsalertnumber => $replacement})->store if $confirm;
68
    } else {
69
        print "Can't find a replacement\n\n";
70
    }
71
}
72
73
=head1 NAME
74
75
check_smsalertnumber - This script check and transform SMS alert number.
76
77
=head1 SYNOPSIS
78
79
check_smsalertnumber.pl -a|--area fr [-h|--help] [-c|--confirm] [-o|--country-option] [-l|--liste-mode]
80
81
Check SMS alert number and transform them if a replacement is found (--confirm). Mode
82
can be found/added in C4/Number. add --list-area option to this script to get the
83
available list.
84
85
=head1 OPTIONS
86
87
=over
88
89
=item B<-h|--help>
90
91
Print a brief help message
92
93
=item B<-a|--area>
94
95
Specify the area template to use. See --list-area to get all available area
96
97
=item B<-c|--confirm>
98
99
If this option is passed to the script, replacement are stored in database
100
101
=item B<-o|--country-option>
102
103
Mode option. Modes could need additional option(s)
104
105
=item B<-l|--list>
106
107
Print a list of available areas
108
109
=back
110
111
=head1 AUTHOR
112
113
Alex Arnaud <alex.arnaud@biblibre.com>
114
115
=head1 COPYRIGHT
116
117
Copyright 2016 BibLibre
118
119
=head1 LICENSE
120
121
This file is part of Koha.
122
123
Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
124
Foundation; either version 3 of the License, or (at your option) any later version.
125
126
You should have received a copy of the GNU General Public License along
127
with Koha; if not, write to the Free Software Foundation, Inc.,
128
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
129
130
=cut

Return to bug 19017