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

(-)a/C4/Letters.pm (-1 / +10 lines)
Lines 30-35 use C4::Log; Link Here
30
use C4::SMS;
30
use C4::SMS;
31
use C4::Debug;
31
use C4::Debug;
32
use Koha::DateUtils;
32
use Koha::DateUtils;
33
use Koha::SMS::Provider;
33
34
34
use Date::Calc qw( Add_Delta_Days );
35
use Date::Calc qw( Add_Delta_Days );
35
use Encode;
36
use Encode;
Lines 742-748 sub SendQueuedMessages { Link Here
742
            _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'} );
743
            _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'} );
743
        }
744
        }
744
        elsif ( lc( $message->{'message_transport_type'} ) eq 'sms' ) {
745
        elsif ( lc( $message->{'message_transport_type'} ) eq 'sms' ) {
745
            _send_message_by_sms( $message );
746
            if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) {
747
                my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
748
                my $sms_provider = Koha::SMS::Provider->find( $member->{'sms_provider_id'} );
749
                $message->{to_address} .= '@' . $sms_provider->domain();
750
                _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'} );
751
            } else {
752
                _send_message_by_sms( $message );
753
            }
746
        }
754
        }
747
    }
755
    }
748
    return scalar( @$unsent_messages );
756
    return scalar( @$unsent_messages );
Lines 955-960 sub _send_message_by_email { Link Here
955
    }
963
    }
956
964
957
    _update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated
965
    _update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated
966
958
    if ( sendmail( %sendmail_params ) ) {
967
    if ( sendmail( %sendmail_params ) ) {
959
        _set_message_status( { message_id => $message->{'message_id'},
968
        _set_message_status( { message_id => $message->{'message_id'},
960
                status     => 'sent' } );
969
                status     => 'sent' } );
(-)a/C4/Members.pm (-1 / +5 lines)
Lines 722-728 sub ModMember { Link Here
722
            $data{password} = md5_base64($data{password});
722
            $data{password} = md5_base64($data{password});
723
        }
723
        }
724
    }
724
    }
725
	my $execute_success=UpdateInTable("borrowers",\%data);
725
726
    $data{'sms_provider_id'} = undef unless ( $data{'sms_provider_id'} );
727
728
    my $execute_success=UpdateInTable("borrowers",\%data);
729
726
    if ($execute_success) { # only proceed if the update was a success
730
    if ($execute_success) { # only proceed if the update was a success
727
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
731
        # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
728
        # so when we update information for an adult we should check for guarantees and update the relevant part
732
        # so when we update information for an adult we should check for guarantees and update the relevant part
(-)a/Koha/SMS/Provider.pm (+157 lines)
Line 0 Link Here
1
package Koha::SMS::Provider;
2
3
# Copyright 2012 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
Koha::SMS::Provider - class to manage sms providers
23
24
=head1 SYNOPSIS
25
26
Object-oriented class that encapsulates sms providers in Koha.
27
28
=head1 DESCRIPTION
29
30
SMS::Provider data.
31
32
=cut
33
34
use Modern::Perl;
35
36
use C4::Context;
37
38
use base qw(Class::Accessor);
39
40
__PACKAGE__->mk_accessors(qw( id name domain ));
41
42
=head2 new
43
44
    my $provider = Koha::SMS::Provider->new($data);
45
46
Create a new Koha::SMS::Provider object based on the provided record.
47
48
=cut
49
50
sub new {
51
    my $class = shift;
52
    my $data  = shift;
53
54
    my $self = $class->SUPER::new($data);
55
56
    bless $self, $class;
57
    return $self;
58
}
59
60
=head2 store
61
62
    Creates or updates the object in the database
63
64
=cut
65
66
sub store {
67
    my $self = shift;
68
69
    if ( $self->id ) {
70
        return C4::Context->dbh->do( "UPDATE sms_providers SET name = ?, domain = ? WHERE id = ?", undef, ( $self->name, $self->domain, $self->id ) );
71
    } else {
72
        return C4::Context->dbh->do( "INSERT INTO sms_providers ( name, domain ) VALUES ( ?, ? )", undef, ( $self->name, $self->domain ) );
73
    }
74
}
75
76
=head2 delete
77
78
=cut
79
80
sub delete {
81
    my $self = shift;
82
83
    return C4::Context->dbh->do( "DELETE FROM sms_providers WHERE id = ?", undef, ( $self->id ) );
84
}
85
86
=head2 all
87
88
    my $providers = Koha::SMS::Provider->all();
89
90
=cut
91
92
sub all {
93
    my $class = shift;
94
95
    my $query = "SELECT * FROM sms_providers ORDER BY name";
96
    my $sth   = C4::Context->dbh->prepare($query);
97
    $sth->execute();
98
99
    my @providers;
100
    while ( my $row = $sth->fetchrow_hashref() ) {
101
        my $p = Koha::SMS::Provider->new($row);
102
        push( @providers, $p );
103
    }
104
105
    return @providers;
106
}
107
108
=head2 find
109
110
  my $provider = Koha::SMS::Provider->find( $id );
111
112
=cut
113
114
sub find {
115
    my $class = shift;
116
    my $id    = shift;
117
118
    my $query = "SELECT * FROM sms_providers WHERE ID = ?";
119
    my $sth   = C4::Context->dbh->prepare($query);
120
    $sth->execute($id);
121
122
    my $row = $sth->fetchrow_hashref();
123
    my $p   = Koha::SMS::Provider->new($row);
124
125
    return $p;
126
}
127
128
=head2 search
129
130
  my @providers = Koha::SMS::Provider->search({ [name => $name], [domain => $domain] });
131
132
=cut
133
134
sub search {
135
    my $class  = shift;
136
    my $params = shift;
137
138
    my $query = "SELECT * FROM sms_providers WHERE ";
139
140
    my @params = map( $params->{$_}, keys %$params );
141
    $query .= join( " AND ", map( "$_ = ?", keys %$params ) );
142
143
    $query .= " ORDER BY name";
144
145
    my $sth = C4::Context->dbh->prepare($query);
146
    $sth->execute(@params);
147
148
    my @providers;
149
    while ( my $row = $sth->fetchrow_hashref() ) {
150
        my $p = Koha::SMS::Provider->new($row);
151
        push( @providers, $p );
152
    }
153
154
    return @providers;
155
}
156
157
1;
(-)a/admin/admin-home.pl (-1 / +4 lines)
Lines 34-39 my ($template, $loggedinuser, $cookie) Link Here
34
			     debug => 1,
34
			     debug => 1,
35
			     });
35
			     });
36
36
37
$template->param( SearchEngine => C4::Context->preference('SearchEngine') );
37
$template->param(
38
    SearchEngine => C4::Context->preference('SearchEngine'),
39
    SMSSendDriver => C4::Context->preference('SMSSendDriver'),
40
);
38
41
39
output_html_with_http_headers $query, $cookie, $template->output;
42
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/installer/data/mysql/kohastructure.sql (-1 / +17 lines)
Lines 262-267 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
262
  `altcontactcountry` text default NULL, -- the country for the alternate contact for the patron/borrower
262
  `altcontactcountry` text default NULL, -- the country for the alternate contact for the patron/borrower
263
  `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
263
  `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
264
  `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
264
  `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
265
  `sms_provider_id` int(11) DEFAULT NULL, -- the provider of the mobile phone number defined in smsalertnumber
265
  `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
266
  `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
266
  UNIQUE KEY `cardnumber` (`cardnumber`),
267
  UNIQUE KEY `cardnumber` (`cardnumber`),
267
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
268
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
Lines 269-276 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
269
  KEY `branchcode` (`branchcode`),
270
  KEY `branchcode` (`branchcode`),
270
  KEY `userid` (`userid`),
271
  KEY `userid` (`userid`),
271
  KEY `guarantorid` (`guarantorid`),
272
  KEY `guarantorid` (`guarantorid`),
273
  KEY `sms_provider_id` (`sms_provider_id`)
272
  CONSTRAINT `borrowers_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`),
274
  CONSTRAINT `borrowers_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`),
273
  CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
275
  CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`),
276
  CONSTRAINT `borrowers_ibfk_3` FOREIGN KEY (`sms_provider_id`) REFERENCES `sms_providers` (`id`)
274
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
277
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
275
278
276
--
279
--
Lines 1817-1822 CREATE TABLE sessions ( Link Here
1817
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1820
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1818
1821
1819
--
1822
--
1823
-- Table structure for table `sms_providers`
1824
--
1825
1826
DROP TABLE IF EXISTS sms_providers;
1827
CREATE TABLE `sms_providers` (
1828
  `id` int(11) NOT NULL AUTO_INCREMENT,
1829
  `name` varchar(255) NOT NULL,
1830
  `domain` varchar(255) NOT NULL,
1831
  PRIMARY KEY (`id`),
1832
  UNIQUE KEY `name` (`name`)
1833
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1834
1835
--
1820
-- Table structure for table `special_holidays`
1836
-- Table structure for table `special_holidays`
1821
--
1837
--
1822
1838
(-)a/installer/data/mysql/updatedatabase.pl (+18 lines)
Lines 6437-6442 if ( CheckVersion($DBversion) ) { Link Here
6437
    SetVersion($DBversion);
6437
    SetVersion($DBversion);
6438
}
6438
}
6439
6439
6440
$DBversion = "3.11.00.XXX";
6441
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
6442
   $dbh->do("
6443
       CREATE TABLE  sms_providers (
6444
           id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
6445
           name VARCHAR( 255 ) NOT NULL ,
6446
           domain VARCHAR( 255 ) NOT NULL ,
6447
           UNIQUE (
6448
               name
6449
           )
6450
       ) ENGINE = INNODB CHARACTER SET utf8;
6451
   ");
6452
   $dbh->do("ALTER TABLE borrowers ADD sms_provider_id INT( 11 ) NULL DEFAULT NULL AFTER smsalertnumber, ADD INDEX ( sms_provider_id )");
6453
   $dbh->do("ALTER TABLE borrowers ADD FOREIGN KEY ( sms_provider_id ) REFERENCES  sms_providers ( id )");
6454
6455
   print "Upgrade to $DBversion done (Add SMS via Email feature)\n";
6456
   SetVersion ($DBversion);
6457
}
6440
6458
6441
=head1 FUNCTIONS
6459
=head1 FUNCTIONS
6442
6460
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-5 / +13 lines)
Lines 101-114 Link Here
101
101
102
<h3>Additional parameters</h3>
102
<h3>Additional parameters</h3>
103
<dl>
103
<dl>
104
	[% IF ( NoZebra ) %]<dt><a href="/cgi-bin/koha/admin/stopwords.pl">Stop words</a></dt>
104
    [% IF ( NoZebra ) %]<dt><a href="/cgi-bin/koha/admin/stopwords.pl">Stop words</a></dt>
105
	<dd>Words ignored during search.</dd>[% END %]
105
        <dd>Words ignored during search.</dd>
106
	<!-- <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
106
    [% END %]
107
	<dd>Printers (UNIX paths).</dd> -->
107
    <!-- <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
108
    <dd>Printers (UNIX paths).</dd> -->
109
108
    <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></dt>
110
    <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></dt>
109
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
111
    <dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
112
110
    <dt><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></dt>
113
    <dt><a href="/cgi-bin/koha/admin/didyoumean.pl">Did you mean?</a></dt>
111
    <dd>Choose which plugins to use to suggest searches to patrons and staff.</dd>
114
    <dd>Choose which plugins to use to suggest searches to patrons and staff.</dd>
115
116
    [% IF SMSSendDriver == 'Email' %]
117
        <dt><a href="/cgi-bin/koha/admin/sms_providers.pl">SMS cellular providers</a></dt>
118
        <dd>Define a list of cellular providers for sending SMS messages via email.</dd>
119
    [% END %]
112
</dl>
120
</dl>
113
</div>
121
</div>
114
122
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (+13 lines)
Lines 1441-1446 Link Here
1441
            <input type="text" id="SMSnumber" name="SMSnumber" value="[% SMSnumber %]" />
1441
            <input type="text" id="SMSnumber" name="SMSnumber" value="[% SMSnumber %]" />
1442
        [% END %]
1442
        [% END %]
1443
        </p>
1443
        </p>
1444
        <p>
1445
            <label for="sms_provider_id">SMS provider:</label>
1446
            <select id="sms_provider_id" name="sms_provider_id"/>
1447
                <option value="">Unknown</option>
1448
                [% FOREACH s IN sms_providers %]
1449
                    [% IF s.id == sms_provider_id %]
1450
                        <option value="[% s.id %]" selected="selected">[% s.name %]</option>
1451
                    [% ELSE %]
1452
                        <option value="[% s.id %]">[% s.name %]</option>
1453
                    [% END %]
1454
                [% END %]
1455
            </select>
1456
        </p>
1444
    [% END %]
1457
    [% END %]
1445
  </fieldset>
1458
  </fieldset>
1446
[% END %] [% END %]
1459
[% END %] [% END %]
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-messaging.tt (-1 / +24 lines)
Lines 143-150 Link Here
143
    </tr>
143
    </tr>
144
    [% END %]
144
    [% END %]
145
  </table>
145
  </table>
146
[% IF ( SMSSendDriver ) %]<ol><li><label for="SMSnumber">SMS number:</label> <input type="text" id="SMSnumber" name="SMSnumber" value="[% SMSnumber %]" /></li></ol>[% END %]
147
146
147
    [% IF ( SMSSendDriver ) %]
148
        <ol><li><label>Notice:</label>Some charges for text messages may be incurred when using this service. Please check with your mobile service provider if you have questions.</li></ol>
149
        <ol><li>
150
            <label for="SMSnumber">SMS number:</label> <input type="text" id="SMSnumber" name="SMSnumber" value="[% SMSnumber %]" />
151
            <i>Please enter numbers only. <b>(123) 456-7890</b> would be entered as <b>1234567890</b>.</i>
152
        </li></ol>
153
    [% END %]
154
155
    [% IF ( SMSSendDriver == 'Email' ) %]
156
        <ol><li>
157
            <label for="sms_provider_id">SMS provider:</label>
158
            <select id="sms_provider_id" name="sms_provider_id"/>
159
                <option value="">Unknown</option>
160
                [% FOREACH s IN sms_providers %]
161
                    [% IF s.id == sms_provider_id %]
162
                        <option value="[% s.id %]" selected="selected">[% s.name %]</option>
163
                    [% ELSE %]
164
                        <option value="[% s.id %]">[% s.name %]</option>
165
                    [% END %]
166
                [% END %]
167
            </select>
168
            <i>Please contact a library staff member if you are unsure of your mobile service provider, or you do not see your provider in this list.</i>
169
        </li></ol>
170
    [% END %]
148
</fieldset>
171
</fieldset>
149
172
150
<fieldset class="action">
173
<fieldset class="action">
(-)a/members/memberentry.pl (+7 lines)
Lines 41-46 use C4::Log; Link Here
41
use C4::Letters;
41
use C4::Letters;
42
use C4::Branch; # GetBranches
42
use C4::Branch; # GetBranches
43
use C4::Form::MessagingPreferences;
43
use C4::Form::MessagingPreferences;
44
use Koha::SMS::Provider;
44
45
45
use vars qw($debug);
46
use vars qw($debug);
46
47
Lines 62-67 my ($template, $loggedinuser, $cookie) Link Here
62
           flagsrequired => {borrowers => 1},
63
           flagsrequired => {borrowers => 1},
63
           debug => ($debug) ? 1 : 0,
64
           debug => ($debug) ? 1 : 0,
64
       });
65
       });
66
67
if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) {
68
    my @providers = Koha::SMS::Provider->all();
69
    $template->param( sms_providers => \@providers );
70
}
71
65
my $guarantorid    = $input->param('guarantorid');
72
my $guarantorid    = $input->param('guarantorid');
66
my $borrowernumber = $input->param('borrowernumber');
73
my $borrowernumber = $input->param('borrowernumber');
67
my $actionType     = $input->param('actionType') || '';
74
my $actionType     = $input->param('actionType') || '';
(-)a/opac/opac-messaging.pl (-2 / +8 lines)
Lines 54-60 if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { Link Here
54
    # If they've modified the SMS number, record it.
54
    # If they've modified the SMS number, record it.
55
    if ( ( defined $query->param('SMSnumber') ) && ( $query->param('SMSnumber') ne $borrower->{'mobile'} ) ) {
55
    if ( ( defined $query->param('SMSnumber') ) && ( $query->param('SMSnumber') ne $borrower->{'mobile'} ) ) {
56
        ModMember( borrowernumber => $borrowernumber,
56
        ModMember( borrowernumber => $borrowernumber,
57
                   smsalertnumber => $query->param('SMSnumber') );
57
                   smsalertnumber => $query->param('SMSnumber'),
58
                   sms_provider_id => $query->param('sms_provider_id')
59
                 );
58
        $borrower = GetMemberDetails( $borrowernumber );
60
        $borrower = GetMemberDetails( $borrowernumber );
59
    }
61
    }
60
62
Lines 70-73 $template->param( BORROWER_INFO => [ $borrower ], Link Here
70
                  SMSSendDriver                =>  C4::Context->preference("SMSSendDriver"),
72
                  SMSSendDriver                =>  C4::Context->preference("SMSSendDriver"),
71
                  TalkingTechItivaPhone        =>  C4::Context->preference("TalkingTechItivaPhoneNotification") );
73
                  TalkingTechItivaPhone        =>  C4::Context->preference("TalkingTechItivaPhoneNotification") );
72
74
75
if ( C4::Context->preference("SMSSendDriver") eq 'Email' ) {
76
    my @providers = Koha::SMS::Provider->all();
77
    $template->param( sms_providers => \@providers, sms_provider_id => $borrower->{'sms_provider_id'} );
78
}
79
73
output_html_with_http_headers $query, $cookie, $template->output;
80
output_html_with_http_headers $query, $cookie, $template->output;
74
- 

Return to bug 9021