From 6fb8ef0d79cc145e0e227a9cd8a606c50ebcea84 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Sat, 25 Jul 2009 10:03:09 +0100 Subject: [PATCH] New Messaging System. This system is indended to replace the old opacnotes and borrowernotes fields in the borrowers table. This system allows an unlimited number of Libraran and OPAC notes to be attached to a borrower. Each note has a message, a message type, the data it was created, and which library created it. Each message can only be deleted by the library that created it unless the syspref AllowAllMessageDeletion has been set. This system may be used simultaneously with the old notes system and does not affect it in any way. A new database table (messages) was added for this feature. The System also allows for pre-defined notes for Borrower records To use these, just create authorised values with the category BOR_NOTES where the Authorized Value is the short description shown in the pulldown, and the description is the text that should be in the note. Original Author: PTFS Contractor This work co-sponsered by Middletown Township Public Library, Middletown, NJ, USA and East Brunswick Public Library, East Brunswick, NJ, USA Signed-off-by: Colin Campbell --- C4/Members.pm | 142 +++++++++++++++++- admin/systempreferences.pl | 1 + circ/add_message.pl | 55 +++++++ circ/circulation.pl | 14 ++ circ/del_message.pl | 53 +++++++ .../data/mysql/en/mandatory/sysprefs.sql | 1 + .../unimarc_standard_systemprefs.sql | 1 + installer/data/mysql/kohastructure.sql | 14 ++ installer/data/mysql/updatedatabase.pl | 16 ++ .../prog/en/modules/circ/circulation.tmpl | 89 ++++++++++- .../opac-tmpl/prog/en/modules/opac-user.tmpl | 12 ++ opac/opac-user.pl | 5 + 12 files changed, 399 insertions(+), 4 deletions(-) create mode 100755 circ/add_message.pl create mode 100755 circ/del_message.pl diff --git a/C4/Members.pm b/C4/Members.pm index 5bb3476559..9ce2001342 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -75,6 +75,11 @@ BEGIN { &GetBorrowersWithIssuesHistoryOlderThan &GetExpiryDate + + &AddMessage + &DeleteMessage + &GetMessages + &GetMessagesCount ); #Modify data @@ -93,7 +98,7 @@ BEGIN { &AddMember &add_member_orgs &MoveMemberToDeleted - &ExtendMemberSubscriptionTo + &ExtendMemberSubscriptionTo ); #Check data @@ -2049,6 +2054,141 @@ sub DebarMember { } +=head2 AddMessage + +=over 4 + +AddMessage( $borrowernumber, $message_type, $message, $branchcode ); + +Adds a message to the messages table for the given borrower. + +Returns: + True on success + False on failure + +=back + +=cut + +sub AddMessage { + my ( $borrowernumber, $message_type, $message, $branchcode ) = @_; + + my $dbh = C4::Context->dbh; + + if ( ! ( $borrowernumber && $message_type && $message && $branchcode ) ) { + return; + } + + my $query = "INSERT INTO messages ( borrowernumber, branchcode, message_type, message ) VALUES ( ?, ?, ?, ? )"; + my $sth = $dbh->prepare($query); + $sth->execute( $borrowernumber, $branchcode, $message_type, $message ); + + return 1; +} + +=head2 GetMessages + +=over 4 + +GetMessages( $borrowernumber, $type ); + +$type is message type, B for borrower, or L for Librarian. +Empty type returns all messages of any type. + +Returns all messages for the given borrowernumber + +=back + +=cut + +sub GetMessages { + my ( $borrowernumber, $type, $branchcode ) = @_; + + if ( ! $type ) { + $type = '%'; + } + + my $dbh = C4::Context->dbh; + + my $query = "SELECT + branches.branchname, + messages.*, + DATE_FORMAT( message_date, '%m/%d/%Y' ) AS message_date_formatted, + messages.branchcode LIKE '$branchcode' AS can_delete + FROM messages, branches + WHERE borrowernumber = ? + AND message_type LIKE ? + AND messages.branchcode = branches.branchcode + ORDER BY message_date DESC"; + my $sth = $dbh->prepare($query); + $sth->execute( $borrowernumber, $type ) ; + my @results; + + while ( my $data = $sth->fetchrow_hashref ) { + push @results, $data; + } + return \@results; + +} + +=head2 GetMessages + +=over 4 + +GetMessagesCount( $borrowernumber, $type ); + +$type is message type, B for borrower, or L for Librarian. +Empty type returns all messages of any type. + +Returns the number of messages for the given borrowernumber + +=back + +=cut + +sub GetMessagesCount { + my ( $borrowernumber, $type, $branchcode ) = @_; + + if ( ! $type ) { + $type = '%'; + } + + my $dbh = C4::Context->dbh; + + my $query = "SELECT COUNT(*) as MsgCount FROM messages WHERE borrowernumber = ? AND message_type LIKE ?"; + my $sth = $dbh->prepare($query); + $sth->execute( $borrowernumber, $type ) ; + my @results; + + my $data = $sth->fetchrow_hashref; + my $count = $data->{'MsgCount'}; + + return $count; +} + + + +=head2 DeleteMessage + +=over 4 + +DeleteMessage( $message_id ); + +=back + +=cut + +sub DeleteMessage { + my ( $message_id ) = @_; + + my $dbh = C4::Context->dbh; + + my $query = "DELETE FROM messages WHERE message_id = ?"; + my $sth = $dbh->prepare($query); + $sth->execute( $message_id ); + +} + END { } # module clean-up code here (global destructor) 1; diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl index fdaaee764d..e8071e9582 100755 --- a/admin/systempreferences.pl +++ b/admin/systempreferences.pl @@ -170,6 +170,7 @@ $tabsysprefs{InProcessingToShelvingCart} = "Circulation"; $tabsysprefs{NewItemsDefaultLocation} = "Circulation"; $tabsysprefs{ReturnToShelvingCart} = "Circulation"; $tabsysprefs{DisplayClearScreenButton} = "Circulation"; +$tabsysprefs{AllowAllMessageDeletion} = "Circulation"; # Staff Client $tabsysprefs{TemplateEncoding} = "StaffClient"; diff --git a/circ/add_message.pl b/circ/add_message.pl new file mode 100755 index 0000000000..b80ade4464 --- /dev/null +++ b/circ/add_message.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +# Copyright 2009 PTFS Inc. +# +# 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 warnings; + +use CGI; + +use C4::Context; +use C4::Auth; +use C4::Output; +use C4::Members; +use C4::Accounts; +use C4::Stats; +use C4::Koha; +use C4::Overdues; +use C4::Branch; # GetBranches + +my $input = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "circ/circulation.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { borrowers => 1 }, + debug => 1, + } +); + +my $borrowernumber = $input->param('borrowernumber'); +my $branchcode = $input->param('branchcode'); +my $message_type = $input->param('message_type'); +my $borrower_message = $input->param('borrower_message'); + +AddMessage( $borrowernumber, $message_type, $borrower_message, $branchcode ); + +print $input->redirect( + "/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber"); diff --git a/circ/circulation.pl b/circ/circulation.pl index de6013a09e..ca4b995a01 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -655,6 +655,9 @@ if ( C4::Context->preference("memberofinstitution") ) { $template->param( issued_itemtypes_count_loop => \@issued_itemtypes_count_loop, + lib_messages_loop => GetMessages( $borrowernumber, 'L', $branch ), + bor_messages_loop => GetMessages( $borrowernumber, 'B', $branch ), + all_messages_del => C4::Context->preference('AllowAllMessageDeletion'), findborrower => $findborrower, borrower => $borrower, borrowernumber => $borrowernumber, @@ -707,6 +710,17 @@ if ($stickyduedate) { my ($picture, $dberror) = GetPatronImage($borrower->{'cardnumber'}); $template->param( picture => 1 ) if $picture; +# get authorised values with type of BOR_NOTES +my @canned_notes; +my $dbh = C4::Context->dbh; +my $sth = $dbh->prepare('SELECT * FROM authorised_values WHERE category = "BOR_NOTES"'); +$sth->execute(); +while ( my $row = $sth->fetchrow_hashref() ) { + push @canned_notes, $row; +} +if ( scalar( @canned_notes ) ) { + $template->param( canned_bor_notes_loop => \@canned_notes ); +} $template->param( debt_confirmed => $debt_confirmed, diff --git a/circ/del_message.pl b/circ/del_message.pl new file mode 100755 index 0000000000..fcf32a734c --- /dev/null +++ b/circ/del_message.pl @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +# Copyright 2009 PTFS Inc. +# +# 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 warnings; + +use CGI; + +use C4::Context; +use C4::Auth; +use C4::Output; +use C4::Members; +use C4::Accounts; +use C4::Stats; +use C4::Koha; +use C4::Overdues; +use C4::Branch; # GetBranches + +my $input = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "circ/circulation.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { borrowers => 1 }, + debug => 1, + } +); + +my $borrowernumber = $input->param('borrowernumber'); +my $message_id = $input->param('message_id'); + +DeleteMessage($message_id); + +print $input->redirect( + "/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber"); diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index 06fe04c681..fdbef70c0e 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -260,3 +260,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACPatronDetails','1','If OFF the patron details tab in the OPAC is disabled.','','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACFinesTab','1','If OFF the patron fines tab in the OPAC is disabled.','','YesNo'); INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('DisplayOPACiconsXSLT', '1', '', 'If ON, displays the format, audience, type icons in XSLT MARC21 results and display pages.', 'YesNo'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo'); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql index 2a53a23f8e..3cb8878a39 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql @@ -259,3 +259,4 @@ INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanatio INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ('DisplayClearScreenButton', '0', '', 'Cette option ajoute un bouton à la page de circulation pour effacer l\'écran', 'YesNo'); INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('HidePatronName', '0', '', 'Active l''affichage du numéro des adhérents à la place de leur nom dans les pages de réservation et du catalogue.', 'YesNo'); INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('DisplayOPACiconsXSLT', '1', '', 'Si activé, affiche le format, le type de public et les icônes de type en XSLT (MARC21)).', 'YesNo'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index cdf7f423c7..eaf47e09c2 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2367,6 +2367,20 @@ CREATE TABLE `item_circulation_alert_preferences` ( KEY `branchcode` (`branchcode`,`categorycode`,`item_type`, `notification`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- +-- Table structure for table `messages` +-- + +CREATE TABLE `messages` ( + `message_id` int(11) NOT NULL auto_increment, + `borrowernumber` int(11) NOT NULL, + `branchcode` varchar(4) default NULL, + `message_type` varchar(1) NOT NULL, + `message` text NOT NULL, + `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`message_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a05fff9996..cc72e8fd26 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -2651,6 +2651,22 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n"; } +$DBversion = '3.01.00.060'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');"); + $dbh->do('DROP TABLE messages'); + $dbh->do("CREATE TABLE messages ( `message_id` int(11) NOT NULL auto_increment, + `borrowernumber` int(11) NOT NULL, + `branchcode` varchar(4) default NULL, + `message_type` varchar(1) NOT NULL, + `message` text NOT NULL, + `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`message_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + + print "Upgrade to $DBversion done ( Added AllowAllMessageDeletion syspref and messages table )\n"; + SetVersion ($DBversion); +} =item DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl index c43201a96f..8b8b9900a1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl @@ -128,6 +128,20 @@ function refocus(calendar) { }; //]]> + + + @@ -137,6 +151,7 @@ function refocus(calendar) { +
@@ -156,6 +171,41 @@ function refocus(calendar) { + +
Patron's account has been renewed until
@@ -336,7 +386,12 @@ No patron matched
-
+
+ + + + +
@@ -474,7 +529,7 @@ No patron matched

Holds waiting:

-
    +
    • "> (), by Hold placed on .
      Waiting at @@ -489,9 +544,37 @@ No patron matched

      Notes:

+ + +
+

Messages:

+ +
@@ -620,7 +703,7 @@ No patron matched - + Previous checkouts Previous checkouts diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl index 3ae68e5b2a..77ee4069c6 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl @@ -75,11 +75,23 @@ $.tablesorter.addParser({
+ + +
+

Messages For You

+
    + +
  • On wrote ""
  • + +
+
+

Hello, (Click here if you're not )

Thank you!

Your corrections have been submitted to the library, and a staff member will update your record as soon as possible.

+

Message from the library

diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 8247f96640..487c136a8a 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -266,7 +266,12 @@ if (C4::Context->preference("OPACAmazonCoverImages") or $template->param(JacketImages=>1); } +if ( GetMessagesCount( $borrowernumber, 'B' ) ) { + $template->param( bor_messages => 1 ); +} + $template->param( + bor_messages_loop => GetMessages( $borrowernumber, 'B', 'NONE' ), waiting_count => $wcount, textmessaging => $borr->{textmessaging}, patronupdate => $patronupdate, -- 2.39.5