Bugzilla – Attachment 45192 Details for
Bug 12772
Add item type and on-hold status to overdue notice/status triggers tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12772 - Overdue rules tool and backend library
Bug-12772---Overdue-rules-tool-and-backend-library.patch (text/plain), 38.63 KB, created by
Eivin Giske Skaaren
on 2015-11-26 19:01:39 UTC
(
hide
)
Description:
Bug 12772 - Overdue rules tool and backend library
Filename:
MIME Type:
Creator:
Eivin Giske Skaaren
Created:
2015-11-26 19:01:39 UTC
Size:
38.63 KB
patch
obsolete
>From 1cdd04ebc2d25dc54d34d5c64d727ec255909d96 Mon Sep 17 00:00:00 2001 >From: mxbeaulieu <maxime.beaulieu@inlibro.com> >Date: Tue, 21 Jul 2015 11:41:16 -0400 >Subject: [PATCH] Bug 12772 - Overdue rules tool and backend library > > modified: C4/Overdues.pm > modified: koha-tmpl/intranet-tmpl/prog/en/modules/tools/overduerules.tt > modified: tools/overduerules.pl >--- > C4/Overdues.pm | 19 +- > .../prog/en/modules/tools/overduerules.tt | 379 +++++++++++-------- > tools/overduerules.pl | 393 +++++++------------- > 3 files changed, 362 insertions(+), 429 deletions(-) > >diff --git a/C4/Overdues.pm b/C4/Overdues.pm >index 047c000..dbf73a5 100644 >--- a/C4/Overdues.pm >+++ b/C4/Overdues.pm >@@ -766,9 +766,9 @@ returns a list of branch codes for branches with overdue rules defined. > sub GetBranchcodesWithOverdueRules { > my $dbh = C4::Context->dbh; > my $branchcodes = $dbh->selectcol_arrayref(q| >- SELECT DISTINCT(branchcode) >- FROM overduerules >- WHERE delay1 IS NOT NULL >+ SELECT DISTINCT b.branchcode >+ FROM branches b, overduerules r >+ WHERE b.branchcode = r.branchcode or r.branchcode = '' > ORDER BY branchcode > |); > if ( $branchcodes->[0] eq '' ) { >@@ -935,17 +935,14 @@ sub RemoveNotifyLine { > =cut > > sub GetOverdueMessageTransportTypes { >- my ( $branchcode, $categorycode, $letternumber ) = @_; >- return unless $categorycode and $letternumber; >+ my ( $overduerules_id ) = @_; >+ return unless $overduerules_id; > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare(" >- SELECT message_transport_type >- FROM overduerules odr LEFT JOIN overduerules_transport_types ott USING (overduerules_id) >- WHERE branchcode = ? >- AND categorycode = ? >- AND letternumber = ? >+ SELECT message_transport_type FROM overduerules_transport_types >+ WHERE overduerules_id = ? > "); >- $sth->execute( $branchcode, $categorycode, $letternumber ); >+ $sth->execute( $overduerules_id ); > my @mtts; > while ( my $mtt = $sth->fetchrow ) { > push @mtts, $mtt; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/overduerules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/overduerules.tt >index e561859..fd96b90 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/overduerules.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/overduerules.tt >@@ -2,177 +2,250 @@ > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Tools › Notice triggers</title> > [% INCLUDE 'doc-head-close.inc' %] >- >+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" /> >+[% INCLUDE 'datatables.inc' %] > <script type="text/javascript"> > //<![CDATA[ >-var tab_map = { "1" : _("First"), "2" : _("Second"), "3" : _("Third")}; >-$(document).ready(function() { >- $('#selectlibrary').find("input:submit").hide(); >- $('#branch').change(function() { >- $('#selectlibrary').submit(); >+function clear_edit(){ >+// var cancel = confirm(_("Are you sure you want to cancel your changes?")); >+// if ( !cancel ) return; >+ edit_value_add(0); // reset add value >+ $('#table_overduerules td').removeClass('highlighted-row'); >+ var edit_row = $("#edit_row"); >+ $(edit_row).find("input").each(function(){ >+ var type = $(this).attr("type"); >+ if (type != "button" && type != "submit" ) { >+ $(this).val(""); >+ $(this).removeAttr("disabled"); >+ } >+ if (type == "checkbox"){ >+ row = document.getElementById('edit_row'); >+ if ($(this).prop('outerHTML').contains('checked="checked"')) { >+ var newOuterHTML = $(this).prop('outerHTML').replace(/checked="checked"/, ''); >+ $(this).prop('outerHTML', newOuterHTML); >+ $(this).checked = true; >+ } >+ } > }); >- $("li>a.tab").each( function(){ >- var id = $(this).attr("data-number"); >- $(this).html(tab_map[id]); >- } ); >- $('#rulestabs').tabs(); >-}); >+ $(edit_row).find("select").removeAttr("disabled"); >+ $(edit_row).find("select option:first").attr("selected", "selected"); >+ $(edit_row).find("td:last input[name='clear']").remove(); >+} >+ >+function edit_value_add(id_overduerules) { >+ var input = document.getElementById('edit_id'); >+ if (id_overduerules != 0) { >+ input.value = "add&overduerules_id=" + id_overduerules; >+ } else { >+ input.value = "add"; >+ } >+} >+ >+ $(document).ready(function() { >+ $('#icons').tabs(); >+ $("#table_overduerules").dataTable($.extend(true, {}, dataTablesDefaults, { >+ "aoColumnDefs": [ >+ { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }, >+ ], >+ "aaSorting": [[ 2, "asc" ]], >+ "iDisplayLength": 100 >+ })); >+ $( "#itemtypeentry" ).validate({ >+ rules: { >+ itemtype: { required: true }, >+ description: { required: true }, >+ rentalcharge: { number: true } >+ } >+ }); >+ $(".editrule").click(function(){ >+ if ( $(edit_row).find("input[type='text'][value!='']").length > 0 ) { >+ var edit = confirm(_("Are you sure you want to edit another rule?")); >+ if (!edit) return false; >+ else clear_edit(); // reset header >+ } >+ $('#table_overduerules td').removeClass('highlighted-row'); >+ $(this).parent().parent().find("td").each(function (i) { >+ $(this).addClass('highlighted-row'); >+ itm = $(this).text(); >+ itm = itm.replace(/^\s*|\s*$/g,''); >+ var current_column = $("#edit_row td:eq("+i+")"); >+ $(current_column).find("input[type='text']").val(itm); >+ // select the corresponding option >+ $(current_column).find("select option").each(function(){ >+ opt = $(this).text().toLowerCase(); >+ opt = opt.replace(/^\s*|\s*$/g,''); >+ if ( opt == itm.toLowerCase() ) { >+ $(this).attr('selected', 'selected'); >+ } >+ }); >+ if(($(this)[0].innerHTML).contains('checked')) { >+ row = document.getElementById('edit_row'); >+ row.cells[i].innerHTML = row.cells[i].innerHTML.replace(/>/, 'checked="checked">'); >+ } >+ }); >+ $("#table_overduerules tr:last td:eq(0) select").attr('disabled', 'disabled'); >+ $("#table_overduerules tr:last td:eq(1) select").attr('disabled', 'disabled'); >+ $("#table_overduerules tr:last td:eq(2) select").attr('disabled', 'disabled'); >+ $("#table_overduerules tr:last td:eq(3) select").attr('disabled', 'disabled'); >+ return false; >+ }); >+ }); > //]]> > </script> >- >+<style type="text/css"> >+fieldset.rows div.toptabs li { clear:none;margin-right:.5em;padding-bottom:0;width:auto; } >+fieldset.rows div.toptabs .ui-tabs-nav li.ui-tabs-active {background-color : #F4F8F9; } >+fieldset.rows .ui-tabs-panel { margin-right : 10px; margin-left : 10px;margin-bottom:10px;} >+fieldset.rows .ui-tabs-nav { margin-left : 10px; } >+</style> > </head> >-<body id="tools_overduerules" class="tools"> >+<body id="tools_overduerules" class="admin"> > [% INCLUDE 'header.inc' %] > [% INCLUDE 'cat-search.inc' %] > >-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › Notice triggers</div> >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › >+</div> > > <div id="doc3" class="yui-t2"> > > <div id="bd"> >- <div id="yui-main"> >- <div class="yui-b"> >+ <div id="yui-main"> >+ <div class="yui-b"> > >- <h1>Defining [% IF ( branch ) %]overdue actions for [% branch %][% ELSE %]default overdue actions[% END %]</h1> >- <div class="help"> >- <p>Delay is the number of days after an checkout is due before an action is triggered. </p> >- <p>If you want Koha to trigger an action (send a letter or restrict a member), a delay value is required.</p> >- <p>Columns must be filled left to right: if the first column is blank, other columns will be ignored. </p> >- </div> >- <form method="post" action="/cgi-bin/koha/tools/overduerules.pl" id="selectlibrary"> >- <label for="branch">Select a library:</label> >- <select id="branch" name="branch"> >- <option value="">Default</option> >- [% FOREACH branchloo IN branchloop %] >- [% IF ( branchloo.selected ) %] >- <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option> >- [% ELSE %] >- <option value="[% branchloo.value %]">[% branchloo.branchname %]</option> >- [% END %] >- [% END %] >- </select> >- <input type="submit" value="Select" /> >- </form> >- [% IF ( ERROR ) %] >- <div class="dialog alert"> >- <h3>Data error</h3> >- <p>The following errors were found. Please correct them and submit again:</p> >- <ul> >- [% IF ( ERRORDELAY ) %] >- <li>Delay [% ERRORDELAY %] for [% BORERR %] patron category has some unexpected characters. There should be only numerical characters. </li> >- [% END %] >- [% IF ( ERRORUSELESSDELAY ) %] >- <li>No letter or restriction action specified for delay [% ERRORUSELESSDELAY %] for [% BORERR %] patron category. If a delay is supplied, either a letter, restrict action, or both should be specified.</li> >- [% END %] >- [% IF ( ERRORORDER ) %] >- <li>The first notice's delay should be less than the second, which should be less than the third for the <strong>[% BORERR %]</strong> patron category </li> >- [% END %] >- </ul> >- </div> >+<form method="post" action="/cgi-bin/koha/tools/overduerules.pl"> >+<input id="edit_id" type="hidden" name="op" value="add" /> >+<input type="hidden" name="edit_overduerules_id" value="0" /> >+<table id="table_overduerules"> >+ <thead> >+ <tr> >+ <th>Branch</th> >+ <th>Category</th> >+ <th>Item type</th> >+ <th>On hold</th> >+ <th>Delay</th> >+ <th>Letter</th> >+ <th>Restrict</th> >+ [% FOREACH mtt IN message_transport_types %] >+ <th scpre="col"> >+ [% SWITCH mtt %] >+ [% CASE 'email' %]Email >+ [% CASE 'print' %]Print >+ [% CASE 'sms' %]SMS >+ [% CASE 'feed' %]Feed >+ [% CASE 'phone' %]Phone >+ [% CASE %]% mtt %] > [% END %] >- [% IF ( table ) %] >- <form method="post" action="/cgi-bin/koha/tools/overduerules.pl"> >- <input type="hidden" name="op" value="save" /> >- <input type="hidden" name="branch" value="[% branch %]" /> >- <h3>Rules for overdue actions: [% IF ( branch ) %][% branch %][% ELSE %] default library [% END %]</h3> >- [% IF ( datasaved ) %]<div class="dialog message">INPUT SAVED</div> [% END %] >- >- <div id="rulestabs" class="toptabs"> >- <ul class="ui-tabs-nav"> >- [% FOR tab IN tabs %] >- <li><a href="#[% tab.id %]" class="tab [% tab.id %]" data-number="[% tab.number %]"></a></li> >- [% END %] >- </ul> >- [% FOR tab IN tabs %] >- <div id="[% tab.id %]"> >- <table> >- <thead> >- <tr> >- <th> </th> >- <th scope="col">Delay</th> >- <th scope="col">Letter</th> >- <th scope="col">Restrict</th> >- [% FOREACH mtt IN message_transport_types %] >- <th scpre="col"> >- [% SWITCH mtt %] >- [% CASE 'email' %] >- Email >- [% CASE 'print' %] >- Print >- [% CASE 'sms' %] >- SMS >- [% CASE 'feed' %] >- Feed >- [% CASE 'phone' %] >- Phone >- [% CASE %] >- [% mtt %] >- [% END %] >- </th> >- [% END %] >- </tr> >- </thead> >- <tbody> >- [% FOREACH value IN tab.values %] >- <tr> >- <th scope="row">[% value.line %]</th> >- <td> >- <input type="text" name="delay[% tab.number %]-[% value.overduename %]" size="5" value="[% value.delay %]" /> >- </td> >- <td> >- <select name="letter[% tab.number %]-[% value.overduename %]"> >- <option value="">No notice</option> >- [% FOREACH letter IN letters %] >- [% IF letter.code == value.selected_lettercode %] >- <option value="[% letter.code %]" selected="selected">[% letter.name %]</option> >- [% ELSE %] >- <option value="[% letter.code %]">[% letter.name %]</option> >- [% END %] >- [% END %] >- </select> >- </td> >- <td> >- [% IF ( value.debarred ) %] >- <input type="checkbox" name="debarred[% tab.number %]-[% value.overduename %]" checked="checked" value="1" /> >- [% ELSE %] >- <input type="checkbox" name="debarred[% tab.number %]-[% value.overduename %]" value="1" /> >- [% END %] >- </td> >- [% FOREACH mtt IN value.message_transport_types %] >- <td> >- [% IF mtt.selected %] >- <input type="checkbox" name="mtt[% tab.number %]-[% value.overduename %]" value="[% mtt.value %]" checked="checked" /> >- [% ELSE %] >- [% IF mtt.value == "sms" and not Koha.Preference("SMSSendDriver") %] >- <input type="checkbox" name="mtt[% tab.number %]-[% value.overduename %]" value="[% mtt.value %]" disabled="disabled" /> >- [% ELSIF mtt.value == "phone" and not Koha.Preference("TalkingTechItivaPhoneNotification") %] >- <input type="checkbox" name="mtt[% tab.number %]-[% value.overduename %]" value="[% mtt.value %]" disabled="disabled" /> >- [% ELSE %] >- <input type="checkbox" name="mtt[% tab.number %]-[% value.overduename %]" value="[% mtt.value %]" /> >- [% END %] >- [% END %] >- </td> >- [% END %] >- </tr> >- [% END %] >- </tbody> >- </table> >- </div> >+ </th> > [% END %] >+ <th>Action</th> >+ </tr> >+ </thead> >+ <thead> >+ <tr id="edit_row"> >+ <td> >+ <select name="branchcode" id="branchcode"> >+ <option value="">All</option> >+ [% FOREACH b IN branches %] >+ <option value="[% b.value.branchcode %]">[% b.value.branchname %]</option> >+ [% END %] >+ </select> >+ </td> >+ <td> >+ <select name="categorycode" id="categorycode"> >+ <option value="">All</option> >+ [% FOREACH c IN categories %] >+ <option value="[% c.value.categorycode %]">[% c.value.description %]</option> >+ [% END %] >+ </select> >+ </td> >+ <td> >+ <select name="itemtype" id="itemtype" style="width:13em;"> >+ <option value="">All</option> >+ [% FOREACH it IN itemtypes %] >+ <option value="[% it.value.itemtype %]">[% it.value.description %]</option> >+ [% END %] >+ </select> >+ </td> >+ <td><input type="checkbox" name="onhold" value="1" /></td> >+ <td><input type="text" name="delay" id="delay" size="3" /></td> >+ <td> >+ <select name="letter" id="letter" style="width:13em;"> >+ <option value="">No notice</option> >+ [% FOREACH letter IN letters %] >+ <option value="[% letter.value.code %]">[% letter.value.name %]</option> >+ [% END %] >+ </select> >+ </td> >+ <td> >+ <input type="checkbox" name="debarred" value="1" /> >+ </td> >+ [% FOREACH mtt IN message_transport_types %] >+ <td> >+ <input type="checkbox" name="mtt-[% mtt %]" value="1" /> >+ </td> >+ [% END %] >+ <td colspan="2"> >+ <input type="hidden" name="branch" value="[% current_branch %]"/> >+ <input type="submit" value="Save" class="submit" /> >+ <input type="button" name="cancel" value="Clear" onclick="clear_edit();return false;" /> >+ </td> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH loo IN loop %] >+ [% UNLESS ( loop.odd ) %] >+ <tr class="highlight">[% ELSE %]<tr>[% END %] >+ <td>[% IF loo.branchname == '' %]All[% ELSE %][% loo.branchname %][% END %]</td> >+ <td>[% IF loo.categorydescription == '' %]All[% ELSE %][% loo.categorydescription %][% END %]</td> >+ <td>[% IF loo.itemtypedescription == '' %]All[% ELSE %][% loo.itemtypedescription %][% END %]</td> >+ <td>[% IF loo.onhold %] >+ <input type="checkbox" name="onhold[% loo.overduerules_id %]" checked="checked" value="1" disabled="disabled"/> >+ [% ELSE %] >+ <input type="checkbox" name="onhold[% loo.overduerules_id %]" value="1" disabled="disabled"/> >+ [% END %] >+ </td> >+ <td>[% loo.delay %]</td> >+ <td>[% IF loo.lettername %][% loo.lettername %][% ELSE %]No notice[% END %]</td> >+ <td>[% IF loo.debarred %] >+ <input type="checkbox" name="debarred[% loo.overduerules_id %]" checked="checked" value="1" disabled="disabled"/> >+ [% ELSE %] >+ <input type="checkbox" name="debarred[% loo.overduerules_id %]" value="1" disabled="disabled"/> >+ [% END %] >+ </td> >+ [% FOREACH mtt IN loo.message_transport_types %] >+ <td> >+ [% IF mtt.selected %] >+ <input type="checkbox" name="mtt[% loo.overduerules_id %]-[% mtt.value %]" value="[% mtt.value %]" checked="checked" disabled="disabled"/> >+ [% ELSE %] >+ [% IF mtt.value == "sms" and not Koha.Preference("SMSSendDriver") %] >+ <input type="checkbox" name="mtt[% loo.overduerules_id %]-[% mtt.value %]" value="[% mtt.value %]" disabled="disabled" /> >+ [% ELSIF mtt.value == "phone" and not Koha.Preference("TalkingTechItivaPhoneNotification") %] >+ <input type="checkbox" name="mtt[% loo.overduerules_id %]-[% mtt.value %]" value="[% mtt.value %]" disabled="disabled" /> >+ [% ELSE %] >+ <input type="checkbox" name="mtt[% loo.overduerules_id %]-[% mtt.value %]" value="[% mtt.value %]" disabled="disabled"/> >+ [% END %] >+ [% END %] >+ </td> >+ [% END %] >+ <td> >+ <a href="#" class="editrule" onclick="edit_value_add([% loo.overduerules_id %])">Edit</a> >+ <a href="[% loo.script_name %]?op=delete&overduerules_id=[% loo.overduerules_id %]">Delete</a> >+ </td> >+ </tr> >+ [% END %] >+ </tbody> >+</table> >+</form> > >+<div class="pages">[% pagination_bar %]</div> > >-</div> > >- <fieldset class="action"><input type="submit" value="Save changes" /></fieldset> >- </form> >- [% ELSE %] >- <div class="warning">You don't have patron categories defined, or the patron categories are not set to receive overdue notices.</div> >- <div class="warning">If this is not what you were expecting, go to <a href="../admin/categorie.pl">patron categories</p></div> >- [% END %] >- </div> >- </div> >- <div class="yui-b noprint"> >- [% INCLUDE 'tools-menu.inc' %] >- </div> >+ >+ >+</div> >+</div> >+<div class="yui-b"> >+[% INCLUDE 'tools-menu.inc' %] >+</div> > </div> > [% INCLUDE 'intranet-bottom.inc' %] >diff --git a/tools/overduerules.pl b/tools/overduerules.pl >index f875dae..15d3618 100755 >--- a/tools/overduerules.pl >+++ b/tools/overduerules.pl >@@ -1,6 +1,6 @@ > #!/usr/bin/perl > >-# Copyright 2000-2002 Katipo Communications >+# Copyright 2014 Solutions inLibro > # > # This file is part of Koha. > # >@@ -20,289 +20,152 @@ > use strict; > use warnings; > use CGI qw ( -utf8 ); >+use List::Util qw/min/; >+use File::Spec; >+use C4::Koha; > use C4::Context; >-use C4::Output; > use C4::Auth; >-use C4::Koha; >-use C4::Branch; >+use C4::Output; > use C4::Letters; >-use C4::Members; >+use C4::Branch; > use C4::Overdues; >+use Data::Dumper; >+ >+sub StringSearch { >+ my ( $searchstring, $type ) = @_; >+ my $dbh = C4::Context->dbh; >+ $searchstring =~ s/\'/\\\'/g; >+ my @data = split( ' ', $searchstring ); >+ my $sth = $dbh->prepare( >+ "SELECT * FROM overduerules WHERE (branchcode LIKE ?) or (categorycode LIKE ?) or (letter LIKE ?) or (itemtype LIKE ?) ORDER BY branchcode, delay" >+ ); >+ $sth->execute("$data[0]%","$data[0]%","$data[0]%","$data[0]%"); >+ return $sth->fetchall_arrayref({}); # return ref-to-array of ref-to-hashes >+ # like [ fetchrow_hashref(), fetchrow_hashref() ... ] >+} > >-our $input = new CGI; >-my $dbh = C4::Context->dbh; >- >-my @categories = @{$dbh->selectall_arrayref( >- 'SELECT description, categorycode FROM categories WHERE overduenoticerequired > 0', >- { Slice => {} } >-)}; >-my @category_codes = map { $_->{categorycode} } @categories; >-our @rule_params = qw(delay letter debarred); >- >-# blank_row($category_code) - return true if the entire row is blank. >-sub blank_row { >- my ($category_code) = @_; >- for my $rp (@rule_params) { >- for my $n (1 .. 3) { >- my $key = "${rp}${n}-$category_code"; >- >- if (utf8::is_utf8($key)) { >- utf8::encode($key); >- } >- >- my $value = $input->param($key); >- if ($value) { >- return 0; >- } >- } >- } >- return 1; >+my $input = new CGI; >+my $searchfield = $input->param('description'); >+my $script_name = "/cgi-bin/koha/tools/overduerules.pl"; >+my $op = $input->param('op'); >+my $overduerules_id = $input->param('overduerules_id'); >+my $branch = $input->param('branchcode'); >+my $cat = $input->param('categorycode'); >+my $itemtype = $input->param('itemtype'); >+my $onhold = $input->param('onhold'); >+my $delay = $input->param('delay') || 1; >+my @mttparams; >+foreach ($input->param){ >+ push (@mttparams, $1) if ($_ =~ /^mtt-(.*)/); > } > >-my $type=$input->param('type'); >-my $branch = $input->param('branch'); >-$branch ||= q{}; >-my $op = $input->param('op'); >-$op ||= q{}; >+$searchfield =~ s/\,//g; >+my ($template, $borrowernumber, $cookie ) = get_template_and_user( >+ { >+ template_name => "tools/overduerules.tt", >+ query => $input, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { parameters => 'edit_notice_status_triggers' }, >+ debug => 1, >+ } >+); > >-my ($template, $loggedinuser, $cookie) >- = get_template_and_user({template_name => "tools/overduerules.tt", >- query => $input, >- type => "intranet", >- authnotrequired => 0, >- flagsrequired => { tools => 'edit_notice_status_triggers'}, >- debug => 1, >- }); >-my $err=0; >+my $dbh = C4::Context->dbh; > >-# save the values entered into tables >-my %temphash; >-my $input_saved = 0; >-if ($op eq 'save') { >- my @names=$input->param(); >- my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM overduerules WHERE branchcode=? AND categorycode=?"); >+# collect the parameters as hashrefs >+my $hrBranches = GetBranches(); >+my $hrUsercats = $dbh->selectall_hashref("SELECT description,categorycode FROM categories WHERE overduenoticerequired = 1", "categorycode"); >+my $hrItemtypes = $dbh->selectall_hashref("SELECT description,itemtype FROM itemtypes ", "itemtype"); >+my $hrLetters = $dbh->selectall_hashref("SELECT name,code FROM letter WHERE module = 'circulation' order by name", "code"); >+my $arMessage_transport_types = C4::Letters::GetMessageTransportTypes(); > >- my $sth_insert = $dbh->prepare("INSERT INTO overduerules (branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3) VALUES (?,?,?,?,?,?,?,?,?,?,?)"); >- my $sth_update=$dbh->prepare("UPDATE overduerules SET delay1=?, letter1=?, debarred1=?, delay2=?, letter2=?, debarred2=?, delay3=?, letter3=?, debarred3=? WHERE branchcode=? AND categorycode=?"); >- my $sth_delete=$dbh->prepare("DELETE FROM overduerules WHERE branchcode=? AND categorycode=?"); >- my $sth_insert_mtt = $dbh->prepare(" >- INSERT INTO overduerules_transport_types( >- overduerules_id, letternumber, message_transport_type >- ) VALUES ( >- (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?), ?, ? >- ) >- "); >- my $sth_delete_mtt = $dbh->prepare(" >- DELETE FROM overduerules_transport_types >- WHERE overduerules_id = (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?) >- "); >+# get everything on the page >+$template->param( >+ script_name => $script_name, >+ branches => $hrBranches, >+ categories => $hrUsercats, >+ itemtypes => $hrItemtypes, >+ letters => $hrLetters, >+ message_transport_types => $arMessage_transport_types, >+); > >- foreach my $key (@names){ >- # ISSUES >- if ($key =~ /(delay|letter|debarred)([1-3])-(.*)/) { >- my $type = $1; # data type >- my $num = $2; # From 1 to 3 >- my $bor = $3; # borrower category >- my $value = $input->param($key); >- if ($type eq 'delay') { >- $temphash{$bor}->{"$type$num"} = ($value =~ /^\d+$/ && int($value) > 0) ? int($value) : ''; >- } else { >- # type is letter >- $temphash{$bor}->{"$type$num"} = $value if $value ne ''; >- } >- } >+# operations >+if ( $op =~ m/add/ ) { >+ $op =~ s/\D//g; >+ $branch = (!defined $branch ) ? '' : $branch; >+ $op = ($op eq '') ? 0 : $op; >+ $cat = (!defined $cat ) ? 0 : $cat; >+ $itemtype = (!defined $itemtype ) ? '' :$itemtype; >+ $onhold = (!defined $onhold ) ? 0 : $onhold; >+ my $debarred = (!defined $input->param('debarred')) ? 0 : $input->param('debarred'); >+ my $ruleId = $dbh->selectrow_array("SELECT overduerules_id from overduerules where branchcode = '$branch' and categorycode = '$cat' and itemtype = '$itemtype' and onhold = '$onhold' and delay = '$delay' "); >+ if ( $ruleId ) {# it's a modification. We update the overrules table and delete corresponding entries in overduerules_transport_types >+ my $query2 = " >+ UPDATE overduerules >+ SET letter = ?, debarred = ? >+ WHERE branchcode = ? and categorycode = ? and itemtype = ? and onhold = ? and delay = ? "; >+ my $sth = $dbh->prepare($query2); >+ $sth->execute($input->param('letter') || '', $debarred , $branch, $cat, $itemtype, $onhold, $delay); >+ $dbh->do("DELETE FROM overduerules_transport_types where overduerules_id = $ruleId"); > } >+ elsif ($op != 0) { # case edit pkeys >+ my $query2 = " >+ UPDATE overduerules >+ SET letter = ?, debarred = ?, branchcode = ?, categorycode = ?, itemtype = ?, onhold = ?, delay = ? >+ WHERE overduerules_id = ? "; >+ my $sth = $dbh->prepare($query2); >+ $sth->execute($input->param('letter') || '', $debarred , $branch, $cat, $itemtype, $onhold, $delay, $op); >+ $dbh->do("DELETE FROM overduerules_transport_types where overduerules_id = $op"); >+ } else { # add a new entry in overrules >+ my $query = " >+ INSERT INTO overduerules (branchcode, categorycode, itemtype, onhold, delay, letter, debarred) >+ VALUES (?,?,?,?,?,?,?);"; >+ my $sth = $dbh->prepare($query); >+ $sth->execute($branch, $cat, $itemtype, $onhold, $delay, $input->param('letter') || '', $debarred); >+ $ruleId = $sth->{mysql_insertid}; > >- # figure out which rows need to be deleted >- my @rows_to_delete = grep { blank_row($_) } @category_codes; >- >- foreach my $bor (keys %temphash){ >- # get category name if we need it for an error message >- my $bor_category = GetBorrowercategory($bor); >- my $bor_category_name = defined($bor_category) ? $bor_category->{description} : $bor; >- >- # Do some Checking here : delay1 < delay2 <delay3 all of them being numbers >- # Raise error if not true >- if ($temphash{$bor}->{delay1}=~/[^0-9]/ and $temphash{$bor}->{delay1} ne ""){ >- $template->param("ERROR"=>1,"ERRORDELAY"=>"delay1","BORERR"=>$bor_category_name); >- $err=1; >- } elsif ($temphash{$bor}->{delay2}=~/[^0-9]/ and $temphash{$bor}->{delay2} ne ""){ >- $template->param("ERROR"=>1,"ERRORDELAY"=>"delay2","BORERR"=>$bor_category_name); >- $err=1; >- } elsif ($temphash{$bor}->{delay3}=~/[^0-9]/ and $temphash{$bor}->{delay3} ne ""){ >- $template->param("ERROR"=>1,"ERRORDELAY"=>"delay3","BORERR"=>$bor_category_name); >- $err=1; >- } elsif ($temphash{$bor}->{delay1} and not ($temphash{$bor}->{"letter1"} or $temphash{$bor}->{"debarred1"})) { >- $template->param("ERROR"=>1,"ERRORUSELESSDELAY"=>"delay1","BORERR"=>$bor_category_name); >- $err=1; >- } elsif ($temphash{$bor}->{delay2} and not ($temphash{$bor}->{"letter2"} or $temphash{$bor}->{"debarred2"})) { >- $template->param("ERROR"=>1,"ERRORUSELESSDELAY"=>"delay2","BORERR"=>$bor_category_name); >- $err=1; >- } elsif ($temphash{$bor}->{delay3} and not ($temphash{$bor}->{"letter3"} or $temphash{$bor}->{"debarred3"})) { >- $template->param("ERROR"=>1,"ERRORUSELESSDELAY"=>"delay3","BORERR"=>$bor_category_name); >- $err=1; >- }elsif ($temphash{$bor}->{delay3} and >- ($temphash{$bor}->{delay3}<=$temphash{$bor}->{delay2} or $temphash{$bor}->{delay3}<=$temphash{$bor}->{delay1}) >- or $temphash{$bor}->{delay2} and ($temphash{$bor}->{delay2}<=$temphash{$bor}->{delay1})){ >- $template->param("ERROR"=>1,"ERRORORDER"=>1,"BORERR"=>$bor_category_name); >- $err=1; >- } >- unless ($err){ >- if (($temphash{$bor}->{delay1} and ($temphash{$bor}->{"letter1"} or $temphash{$bor}->{"debarred1"})) >- or ($temphash{$bor}->{delay2} and ($temphash{$bor}->{"letter2"} or $temphash{$bor}->{"debarred2"})) >- or ($temphash{$bor}->{delay3} and ($temphash{$bor}->{"letter3"} or $temphash{$bor}->{"debarred3"}))) { >- $sth_search->execute($branch,$bor); >- my $res = $sth_search->fetchrow_hashref(); >- if ($res->{'total'}>0) { >- $sth_update->execute( >- ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:undef), >- ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""), >- ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0), >- ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:undef), >- ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""), >- ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0), >- ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:undef), >- ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""), >- ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0), >- $branch ,$bor >- ); >- } else { >- $sth_insert->execute($branch,$bor, >- ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:0), >- ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""), >- ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0), >- ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:0), >- ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""), >- ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0), >- ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:0), >- ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""), >- ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0) >- ); >- } >- >- $sth_delete_mtt->execute( $branch, $bor ); >- for my $letternumber ( 1..3 ) { >- my @mtt = $input->param( "mtt${letternumber}-$bor" ); >- next unless @mtt; >- for my $mtt ( @mtt ) { >- $sth_insert_mtt->execute( $branch, $bor, $letternumber, $mtt); >- } >- } >- } >- } > } >- unless ($err) { >- for my $category_code (@rows_to_delete) { >- $sth_delete->execute($branch, $category_code); >- } >- $template->param(datasaved => 1); >- $input_saved = 1; >+ # following an update or an insert, we have to insert into overduerules_transport_types >+ my $sth = $dbh->prepare("INSERT INTO overduerules_transport_types (message_transport_type, overduerules_id) values (?,?)"); >+ foreach my $newMtt (@mttparams){ >+ $sth->execute($newMtt, $ruleId); > } >+ print $input->redirect('overduerules.pl'); >+ exit; > } >-my $branchloop = GetBranchesLoop($branch); >- >-my $letters = C4::Letters::GetLettersAvailableForALibrary( >- { >- branchcode => $branch, >- module => "circulation", >- } >-); >- >-my @line_loop; >- >-my $message_transport_types = C4::Letters::GetMessageTransportTypes(); >-my ( @first, @second, @third ); >-for my $data (@categories) { >- if (%temphash and not $input_saved){ >- # if we managed to save the form submission, don't >- # reuse %temphash, but take the values from the >- # database - this makes it easier to identify >- # bugs where the form submission was not correctly saved >- for my $i ( 1..3 ){ >- my %row = ( >- overduename => $data->{'categorycode'}, >- line => $data->{'description'} >- ); >- $row{delay}=$temphash{$data->{'categorycode'}}->{"delay$i"}; >- $row{debarred}=$temphash{$data->{'categorycode'}}->{"debarred$i"}; >- $row{selected_lettercode} = $temphash{ $data->{categorycode} }->{"letter$i"}; >- my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) }; >- my @mtts; >- for my $mtt ( @$message_transport_types ) { >- push @mtts, { >- value => $mtt, >- selected => ( grep {/$mtt/} @selected_mtts ) ? 1 : 0 , >- } >- } >- $row{message_transport_types} = \@mtts; >- if ( $i == 1 ) { >- push @first, \%row; >- } elsif ( $i == 2 ) { >- push @second, \%row; >- } else { >- push @third, \%row; >- } >- } >- } else { >- #getting values from table >- my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?"); >- $sth2->execute($branch,$data->{'categorycode'}); >- my $dat=$sth2->fetchrow_hashref; >- for my $i ( 1..3 ){ >- my %row = ( >- overduename => $data->{'categorycode'}, >- line => $data->{'description'} >- ); >- >- $row{selected_lettercode} = $dat->{"letter$i"}; >- >- if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};} >- if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};} >- my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) }; >- my @mtts; >- for my $mtt ( @$message_transport_types ) { >- push @mtts, { >- value => $mtt, >- selected => ( grep {/$mtt/} @selected_mtts ) ? 1 : 0 , >- } >- } >- $row{message_transport_types} = \@mtts; >- if ( $i == 1 ) { >- push @first, \%row; >- } elsif ( $i == 2 ) { >- push @second, \%row; >- } else { >- push @third, \%row; >+elsif ( $op eq 'delete' ) { >+ my $sth1 = $dbh->prepare("delete from overduerules_transport_types where overduerules_id = ?"); >+ my $sth2 = $dbh->prepare("delete from overduerules where overduerules_id = ?"); >+ $sth1->execute($overduerules_id); >+ $sth2->execute($overduerules_id); >+ print $input->redirect('overduerules.pl'); >+ exit; >+} >+else { # default >+ my ($results) = StringSearch( $searchfield ); >+ my @loop; >+ foreach my $rule ( @{$results} ) { >+ $rule->{branchname} = $hrBranches->{$rule->{branchcode}}->{branchname}; >+ $rule->{lettername} = $hrLetters->{$rule->{letter}}->{name}; >+ $rule->{categorydescription} = $hrUsercats->{$rule->{categorycode}}->{description}; >+ $rule->{itemtypedescription} = $hrItemtypes->{$rule->{itemtype}}->{description}; >+ >+ my @selected_mtts = @{ GetOverdueMessageTransportTypes( $rule->{overduerules_id} ) }; >+ my @mtts; >+ for my $mtt ( @$arMessage_transport_types ) { >+ push @mtts, { >+ value => $mtt, >+ selected => ( grep {/$mtt/} @selected_mtts ) ? 1 : 0 , > } >- > } >+ $rule->{message_transport_types} = \@mtts; >+ push( @loop, $rule ); > } >-} > >-my @tabs = ( >- { >- id => 'first', >- number => 1, >- values => \@first, >- }, >- { >- id => 'second', >- number => 2, >- values => \@second, >- }, >- { >- id => 'third', >- number => 3, >- values => \@third, >- }, >-); >+ $template->param( >+ loop => \@loop, >+ ); >+} > >-$template->param( >- table => ( @first or @second or @third ? 1 : 0 ), >- branchloop => $branchloop, >- branch => $branch, >- tabs => \@tabs, >- message_transport_types => $message_transport_types, >- letters => $letters, >-); > output_html_with_http_headers $input, $cookie, $template->output; >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12772
:
41477
|
41478
|
41479
|
41480
|
41855
|
42126
|
45184
|
45185
|
45186
|
45187
|
45188
|
45189
|
45190
|
45191
|
45192
|
45193
|
45194
|
45195
|
45196
|
45197
|
45198
|
45199
|
45200
|
45201
|
45202
|
45203
|
45204
|
45544
|
45545
|
45546
|
45547
|
45548
|
45549
|
45550
|
45551
|
45552
|
56063
|
56077