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) { +