3 # Copyright 2008 LibLime
5 # This file is part of Koha.
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
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.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Members::Messaging;
35 use C4::Branch; # GetBranchName
36 use C4::Form::MessagingPreferences;
43 $debug = $ENV{DEBUG} || 0;
46 my $dbh = C4::Context->dbh;
48 my $query = CGI->new();
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
52 template_name => 'members/messaging.tmpl',
56 flagsrequired => { borrowers => 1 },
60 my $borrowernumber = $query->param('borrowernumber');
61 my $borrower = GetMember( $borrowernumber ,'borrowernumber');
62 my $branch = C4::Context->userenv->{'branch'};
64 $template->param( $borrower );
66 my $borrower = GetMemberDetails( $borrowernumber );
68 if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
70 # If they've modified the SMS number, record it.
71 if ( ( defined $query->param('SMSnumber') ) && ( $query->param('SMSnumber') ne $borrower->{'mobile'} ) ) {
72 ModMember( borrowernumber => $borrowernumber,
73 smsalertnumber => $query->param('SMSnumber') );
74 $borrower = GetMemberDetails( $borrowernumber );
76 C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $borrowernumber }, $template);
79 C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template);
81 if ( $borrower->{'category_type'} eq 'C') {
82 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
83 my $cnt = scalar(@$catcodes);
84 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
85 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
88 my ($picture, $dberror) = GetPatronImage($borrower->{'cardnumber'});
89 $template->param( picture => 1 ) if $picture;
91 # get some recent messages sent to this borrower for display:
92 my $message_queue = C4::Letters::GetQueuedMessages( { borrowernumber => $query->param('borrowernumber') } );
94 $template->param( messagingview => 1,
95 message_queue => $message_queue,
96 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
97 borrowernumber => $borrowernumber,
98 branchcode => $borrower->{'branchcode'},
99 branchname => GetBranchName($borrower->{'branchcode'}),
100 dateformat => C4::Context->preference("dateformat"),
101 categoryname => $borrower->{'description'},
102 $borrower->{'categorycode'} => 1,
103 SMSSendDriver => C4::Context->preference("SMSSendDriver")
106 #$messaging_preferences->{'SMSnumber'}{'value'} = defined $borrower->{'smsalertnumber'}
107 # ? $borrower->{'smsalertnumber'} : $borrower->{'mobile'};
109 $template->param( BORROWER_INFO => [ $borrower ],
111 is_child => ($borrower->{'category_type'} eq 'C'),
112 SMSnumber => defined $borrower->{'smsalertnumber'} ? $borrower->{'smsalertnumber'} : $borrower->{'mobile'} );
114 output_html_with_http_headers $query, $cookie, $template->output;