Skip to content

Commit

Permalink
Bug 2176 (5/5): adding staff interface to patron messaging preferences
Browse files Browse the repository at this point in the history
I added another tab to the "patron" area of the staff interface to let staff
edit patron messaging preferences.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
  • Loading branch information
amoore authored and Joshua Ferraro committed Jun 20, 2008
1 parent 4d0e0fe commit 3aafdf7
Show file tree
Hide file tree
Showing 3 changed files with 381 additions and 0 deletions.
3 changes: 3 additions & 0 deletions koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc
Expand Up @@ -61,6 +61,9 @@
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="intranetreadinghistory" --><!-- TMPL_IF NAME="readingrecordview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/members/readingrec.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Circulation History</a></li><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="CAN_user_parameters"--><!-- TMPL_IF NAME="logview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/tools/viewlog.pl?do_it=1&amp;module=MEMBERS&amp;action=MODIFY&amp;object=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;src=circ">Modification Log</a></li><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="EnhancedMessagingPreferences" -->
<!-- TMPL_IF NAME="messagingview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/members/messaging.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Messaging</a></li>
<!-- /TMPL_IF -->
</ul></div>
<!-- /TMPL_IF -->

228 changes: 228 additions & 0 deletions koha-tmpl/intranet-tmpl/prog/en/modules/members/messaging.tmpl
@@ -0,0 +1,228 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Patrons &rsaquo; <!-- TMPL_IF NAME="unknowuser" -->Patron does not exist<!-- TMPL_ELSE -->Patron Details for <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> (<!-- TMPL_VAR NAME="cardnumber" -->)<!-- /TMPL_IF --></title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<!-- TMPL_INCLUDE NAME="calendar.inc" -->
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.checkboxes.pack.js"></script>
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
$.tablesorter.addParser({
id: 'articles',
is: function(s) {return false; },
format: function(s) { return s.toLowerCase().replace(/^(the|an|a) /,''); },
type: 'text'
});
$(document).ready(function() {
$('#finesholdsissues > ul').tabs();
$("#issuest").tablesorter({<!-- TMPL_IF EXPR="dateformat eq 'metric'" -->
dateFormat: 'uk',<!-- /TMPL_IF -->
sortList: [[1,0]],
headers: { 1: { sorter: 'articles' },4:{sorter:false},5: { sorter: false },6:{sorter:false},7:{sorter:false}}
});
$("#holdst").tablesorter({<!-- TMPL_IF EXPR="dateformat eq 'metric'" -->
dateFormat: 'uk',<!-- /TMPL_IF -->
sortList: [[0,0]],
headers: { 1: { sorter: 'articles' },6: { sorter: false }}
});
$('#manage-patron-image').find("input[@value*=Delete]").click(function(){
return confirm('Are you sure you want to delete this patron image? This cannot be undone.');
});<!-- TMPL_IF NAME="picture" -->
$('#manage-patron-image').find("input[@value*=Upload]").click(function(){
if($("#uploadfile").val() == ""){
alert("Please choose a file to upload");
return false;
} else {
return confirm('Are you sure you want to replace the current patron image? This cannot be undone.');
}
});<!-- /TMPL_IF -->
$("#renew_all").click(function(){ $(".checkboxed").checkCheckboxes(":not(input[@name*=barcodes])"); $(".checkboxed").unCheckCheckboxes(":not(input[@name*=items])"); });
$("#return_all").click(function(){ $(".checkboxed").checkCheckboxes(":not(input[@name*=items])"); $(".checkboxed").unCheckCheckboxes(":not(input[@name*=barcodes])"); });
$("#CheckAllitems").click(function(){ $(".checkboxed").checkCheckboxes(":not(input[@name*=barcodes])"); $(".checkboxed").unCheckCheckboxes(":not(input[@name*=items])"); return false; });
$("#CheckNoitems").click(function(){ $(".checkboxed").unCheckCheckboxes(":not(input[@name*=barcodes])"); return false; });
$("#CheckAllreturns").click(function(){ $(".checkboxed").checkCheckboxes(":not(input[@name*=items])"); $(".checkboxed").unCheckCheckboxes(":not(input[@name*=barcodes])"); return false; });
$("#CheckNoreturns").click(function(){ $(".checkboxed").unCheckCheckboxes(":not(input[@name*=items])"); return false; });
});
function uncheck_sibling(me){
nodename=me.getAttribute("name");
if (nodename =="barcodes[]"){
var Node=me.parentNode.previousSibling;
while (Node.nodeName!="TD"){Node=Node.previousSibling}
var Nodes=Node.childNodes;
for (var i=0;i<Nodes.length;i++){
if (Nodes[i].nodeName=="INPUT" && Nodes[i].getAttribute("type")=="checkbox"){
Nodes[i].checked=false;
}
}

}else {
var Node=me.parentNode.nextSibling;
while (Node.nodeName!="TD"){Node=Node.nextSibling}
var Nodes=Node.childNodes;
for (var i=0;i<Nodes.length;i++){
if (Nodes[i].nodeName=="INPUT" && Nodes[i].getAttribute("type")=="checkbox"){
Nodes[i].checked=false;
}
}
}
}
//]]>
</script>

</head>
<body>
<!-- TMPL_INCLUDE NAME="header.inc" -->
<!-- TMPL_INCLUDE NAME="patron-search.inc" -->

<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a> &rsaquo; <!-- TMPL_IF NAME="unknowuser" -->Patron does not exist<!-- TMPL_ELSE -->Patron Details for <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> (<!-- TMPL_VAR NAME="cardnumber" -->)<!-- /TMPL_IF --> </div>

<div id="doc3" class="yui-t1">

<div id="bd">
<div id="yui-main">
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="members-toolbar.inc" -->
<!-- TMPL_IF NAME="error" -->
<div class="dialog alert">
<!-- TMPL_IF NAME="AUTH_UPDATE_FAILED" -->
<h3>Userid / Password update failed</h3>
<strong>Insufficient privileges.</strong>
<p>Other fields updated.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="CANT_DELETE_STAFF" -->
<h3>Unable to delete staff user</h3>
<p>Insufficient privileges.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="CANT_DELETE_OTHERLIBRARY" -->
<h3>Unable to delete patrons from other libraries with current settings</h3>
<p>Insufficient privileges.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="CANT_DELETE" -->
<h3>Unable to delete patron:</h3>
<p>Insufficient privileges.</p>
<!-- /TMPL_IF -->
</div>
<!-- /TMPL_IF -->
<div class="yui-g">
<!-- TMPL_IF NAME="unknowuser" -->
<div class="dialog message">
This patron does not exist.
</div>
<!-- TMPL_ELSE -->

<div class="yui-u first">

<form method="get" name="messaging">

<input type="hidden" name="modify" value="yes" />
<input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR NAME="borrowernumber" -->" />
<fieldset class="brief"><legend>Manage patron messaging settings</legend>
<!-- TMPL_IF NAME= "settings_updated" -->
<div class="dialog message"><h1>Settings Updated</h1>
The patron settings have been updated</div>
<!-- /TMPL_IF -->
<table>
<tr><TH></TH><TH># days in advance</TH><TH>sms</TH><TH>email</TH><TH>Digests only?</TH><TH>rss</TH><TH>do not notify</TH></tr>
<!-- TMPL_LOOP name="messaging_preferences" -->
<tr>
<td><label for="firstname"><!-- TMPL_VAR NAME="message_name" --></label></td>
<!-- TMPL_IF NAME="takes_days" -->
<td><SELECT name="<!-- TMPL_VAR NAME="message_attribute_id" -->-DAYS" id="<!-- TMPL_VAR NAME="message_name" -->-DAYS" >
<!-- TMPL_LOOP name="select_days" -->
<OPTION VALUE="<!-- TMPL_VAR NAME="day" -->" <!-- TMPL_VAR NAME="selected" --> ><!-- TMPL_VAR NAME="day" --></OPTION>
<!-- /TMPL_LOOP -->
</SELECT>
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="transport-sms" -->
<td><input type="checkbox"
id="sms<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="sms" <!-- TMPL_VAR NAME="transport-sms" -->
onclick = "document.messaging.none<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false;">
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->

<!-- TMPL_IF NAME="transport-email" -->
<td><input type="checkbox"
id="email<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="email" <!-- TMPL_VAR NAME="transport-email" -->
onclick = "document.messaging.none<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false;">
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->

<!-- TMPL_IF NAME="has_digest" -->
<td><input type="checkbox"
id="digest<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="digest" <!-- TMPL_VAR NAME="digest" -->
onclick = "document.messaging.none<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false;">
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->

<!-- TMPL_IF NAME="transport-rss" -->
<td><input type="checkbox"
id="rss<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="rss" <!-- TMPL_VAR NAME="transport-rss" -->
onclick = "document.messaging.none<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false;">
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->

<td><input type="checkbox" id="none<!-- TMPL_VAR NAME="message_attribute_id" -->"
onclick = "if ( document.messaging.none<!-- TMPL_VAR NAME="message_attribute_id" -->.checked == true ) {
document.messaging.sms<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false;
document.messaging.email<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false;
document.messaging.digest<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false;
document.messaging.rss<!-- TMPL_VAR NAME="message_attribute_id" -->.checked=false; }" /></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
SMS number: <input type="text" name="SMSnumber" value="<!-- TMPL_VAR NAME="SMSnumber" -->" />

</fieldset>


<fieldset class="action">
<input type="submit" value="Submit Changes" /> <a class="cancel" href="/cgi-bin/koha/opac-user.pl">Cancel</a>
</fieldset>
<br />

<!-- TMPL_IF NAME="message_queue" -->
<table>
<CAPTION>Message Queue</CAPTION>
<tr><tH>Type</TH><TH>Subject</TH><TH>Status</TH><TH>Time Prepared</TH></tr>
<!-- TMPL_LOOP name="message_queue" -->
<tr><td><!-- TMPL_VAR NAME="message_transport_type" --></td><td><!-- TMPL_VAR NAME="subject" --></td><td><!-- TMPL_VAR NAME="status" --></td><td><!-- TMPL_VAR NAME="time_queued" --></td></tr>
<!-- /TMPL_LOOP -->
</table>
<!-- /TMPL_IF -->

</form>

<!-- -->


</div>
</div>

<!-- /TMPL_IF --> <!-- unknowuser -->


</div>
</div>
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="circ-menu.inc" -->
</div>
</div>
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
150 changes: 150 additions & 0 deletions members/messaging.pl
@@ -0,0 +1,150 @@
#!/usr/bin/perl

# Copyright 2008 LibLime
#
# This file is part of Koha.
#
# 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
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA


use strict;
use CGI;
use C4::Context;
use C4::Auth;
use C4::Output;
use C4::Members;
use C4::Members::Messaging;
use C4::Dates;
use C4::Reserves;
use C4::Circulation;
use C4::Koha;
use C4::Letters;
use C4::Biblio;
use C4::Reserves;
use C4::Branch; # GetBranchName

use Data::Dumper;

use vars qw($debug);

BEGIN {
$debug = $ENV{DEBUG} || 0;
}

my $dbh = C4::Context->dbh;

my $query = CGI->new();

my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => 'members/messaging.tmpl',
query => $query,
type => "intranet",
authnotrequired => 0,
flagsrequired => { borrowers => 1 },
debug => 1,
}
);
my $borrowernumber = $query->param('borrowernumber');
my $borrower = GetMember( $borrowernumber ,'borrowernumber');
my $branch = C4::Context->userenv->{'branch'};

$template->param( $borrower );

my $borrower = GetMemberDetails( $borrowernumber );

my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
my $messaging_preferences;

if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {

# If they've modified the SMS number, record it.
if ( ( defined $query->param('SMSnumber') ) && ( $query->param('SMSnumber') ne $borrower->{'mobile'} ) ) {
ModMember( borrowernumber => $borrowernumber,
smsalertnumber => $query->param('SMSnumber') );
$borrower = GetMemberDetails( $borrowernumber );
}

# TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box

# warn( Data::Dumper->Dump( [ $messaging_options ], [ 'messaging_options' ] ) );
OPTION: foreach my $option ( @$messaging_options ) {
# warn( Data::Dumper->Dump( [ $option ], [ 'option' ] ) );
my $updater = { borrowernumber => $borrower->{'borrowernumber'},
message_attribute_id => $option->{'message_attribute_id'} };

# find the desired transports
@{$updater->{'message_transport_types'}} = $query->param( $option->{'message_attribute_id'} );
next OPTION unless $updater->{'message_transport_types'};

if ( $option->{'has_digest'} ) {
if ( List::Util::first { $_ == $option->{'message_attribute_id'} } $query->param( 'digest' ) ) {
$updater->{'wants_digest'} = 1;
}
}

if ( $option->{'takes_days'} ) {
if ( defined $query->param( $option->{'message_attribute_id'} . '-DAYS' ) ) {
$updater->{'days_in_advance'} = $query->param( $option->{'message_attribute_id'} . '-DAYS' );
}
}

warn( 'calling SetMessaginPreferencse with ' . Data::Dumper->Dump( [ $updater ], [ 'updater' ] ) );
C4::Members::Messaging::SetMessagingPreference( $updater );
}

# show the success message
$template->param( settings_updated => 1 );
}

# walk through the options and update them with these borrower_preferences
PREF: foreach my $option ( @$messaging_options ) {
my $pref = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrower->{'borrowernumber'},
message_name => $option->{'message_name'} } );
warn( Data::Dumper->Dump( [ $pref ], [ 'pref' ] ) );
# make a hashref of the days, selecting one.
if ( $option->{'takes_days'} ) {
@{$option->{'select_days'}} = map {; { day => $_,
selected => $_ == $pref->{'days_in_advance'} ? 'SELECTED' :'' } } ( 0..30 ); # FIXME: 30 is a magic number.
}
foreach my $transport ( @{$pref->{'transports'}} ) {
$option->{'transport-'.$transport} = 'CHECKED';
}
$option->{'digest'} = 'CHECKED' if $pref->{'wants_digest'};
}


# get some recent messages sent to this borrower for display:
my $message_queue = C4::Letters::GetQueuedMessages( { borrowernumber => $query->param('borrowernumber') } );

$template->param( messagingview => 1,
messaging_preferences => [ $messaging_preferences ],
message_queue => $message_queue,
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
borrowernumber => $borrowernumber,
branch => $branch,
dateformat => C4::Context->preference("dateformat"),
categoryname => $borrower->{'description'},
$borrower->{'categorycode'} => 1,
);

$messaging_preferences->{'SMSnumber'}{'value'} = defined $borrower->{'smsalertnumber'}
? $borrower->{'smsalertnumber'} : $borrower->{'mobile'};

$template->param( BORROWER_INFO => [ $borrower ],
messagingview => 1,
messaging_preferences => $messaging_options,
SMSnumber => defined $borrower->{'smsalertnumber'} ? $borrower->{'smsalertnumber'} : $borrower->{'mobile'} );

output_html_with_http_headers $query, $cookie, $template->output;

0 comments on commit 3aafdf7

Please sign in to comment.