@@ -, +, @@ comments -1. Run updatedatabase.pl to add the syspref and the new letter template. default message. You can change the message in tools/letter.pl. alone: - lacked unit tests since it modified C4/Review.pm - failed to provide the desired links in the email message, as mentioned in comment #1. - failed to pass biblionumber information for use in the letter as mentioned in comment #11. - passed $review, when it was really id that should have been passed and used to implement the inclusion of reviews.reviewid and other reviews table fields. --- C4/Review.pm | 40 ++++++++++++++++++++ .../data/mysql/en/mandatory/sample_notices.sql | 11 ++++++ installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 24 ++++++++++++ .../prog/en/modules/admin/preferences/opac.pref | 4 ++ 5 files changed, 80 insertions(+) --- a/C4/Review.pm +++ a/C4/Review.pm @@ -81,6 +81,10 @@ sub savereview { (?,?,?,0,now())"; my $sth = $dbh->prepare($query); $sth->execute( $borrowernumber, $biblionumber, $review); + + unless ($sth->err()) { + SendReviewAlert( $review, $borrowernumber ); + } } sub updatereview { @@ -89,6 +93,10 @@ sub updatereview { my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0 WHERE borrowernumber=? and biblionumber=?"; my $sth = $dbh->prepare($query); $sth->execute( $review, $borrowernumber, $biblionumber ); + + unless ($sth->err()) { + SendReviewAlert( $review, $borrowernumber ); + } } sub numberofreviews { @@ -186,6 +194,38 @@ sub deletereview { $sth->execute($reviewid); } +=head2 SendReviewAlert + + SendReviewAlert( $review, $borrowernumber ); + +=cut + +sub SendReviewAlert { + my $review = shift; + my $borrowernumber = shift; + + my $moderatorEmail = C4::Context->preference('CommentModeratorsEmail'); + + return unless $moderatorEmail; + + my $letter = C4::Letters::GetPreparedLetter ( + module => 'members', + letter_code => 'COMMENT_CREATED', + tables => { + 'borrowers' => $borrowernumber, + } + ) or return; + + C4::Letters::EnqueueLetter({ + letter => $letter, + borrowernumber => $borrowernumber, + message_transport_type => 'email', + to_address => $moderatorEmail, + }); + + return 1; +} + 1; __END__ --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ a/installer/data/mysql/en/mandatory/sample_notices.sql @@ -118,6 +118,17 @@ http://<>/cgi-bin/koha/opac-registration-verify.pl?token=<> is waiting for moderation', 'Dear moderator, + +We want to inform you that borrower <> has just created a new comment. + +Check it out! + +Your library.', +'email' +); + INSERT INTO letter (module, code, branchcode, name, is_html, title, content) VALUES ('members', 'SHARE_INVITE', '', 'Invitation for sharing a list', '0', 'Share list <>', 'Dear patron, --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -88,6 +88,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('CircAutoPrintQuickSlip','qslip',NULL,'Choose what should happen when an empty barcode field is submitted in circulation: Display a print quick slip window, Display a print slip window or Clear the screen.','Choice'), ('CircControl','ItemHomeLibrary','PickupLibrary|PatronLibrary|ItemHomeLibrary','Specify the agency that controls the circulation and fines policy','Choice'), ('COinSinOPACResults','1','','If ON, use COinS in OPAC search results page. NOTE: this can slow down search response time significantly','YesNo'), +('CommentModeratorsEmail','','','The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications.','Textarea'), ('ConfirmFutureHolds','0','','Number of days for confirming future holds','Integer'), ('CurrencyFormat','US','US|FR','Determines the display format of currencies. eg: \'36000\' is displayed as \'360 000,00\' in \'FR\' or \'360,000.00\' in \'US\'.','Choice'), ('dateformat','us','metric|us|iso','Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd)','Choice'), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -8314,6 +8314,30 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.17.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q| +INSERT INTO letter (module, code, branchcode, name, is_html, title, content, message_transport_type) +VALUES ( 'members', 'COMMENT_CREATED', '', 'Comment created notification', '0', 'Comment from <> is waiting for moderation', 'Dear moderator, + +We want to inform you that borrower <> has just created a new comment. + +Check it out! + +Your library.', +'email' +); + |); + $dbh->do(q| + INSERT INTO systempreferences + (variable,value,explanation,options,type) + VALUES + ('CommentModeratorsEmail','','','The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications.','Textarea') + |); + print "Upgrade to $DBversion done (Bug 1985 - Email notification of new OPAC comments)\n"; + SetVersion($DBversion); +} + $DBversion = "3.15.00.041"; if ( CheckVersion($DBversion) ) { my $name = $dbh->selectcol_arrayref(q| --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -415,6 +415,10 @@ OPAC: no: Hide - reviewer's photo beside comments in OPAC. - + - The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications. + - pref: CommentModeratorsEmail + class: textarea + - - pref: RequestOnOpac choices: yes: Allow --