Added combined, line-wise smart-rules script for defining issuingrules.
authorPianohacker <pianohacker@gmail.com>
Fri, 22 Feb 2008 19:01:03 +0000 (08:01 +1300)
committerJoshua Ferraro <jmf@liblime.com>
Sat, 23 Feb 2008 03:49:10 +0000 (21:49 -0600)
Also added template for "prog" set, and modified admin-home and -menu accordingly.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
admin/smart-rules.pl [new file with mode: 0755]
koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl [new file with mode: 0644]

diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl
new file mode 100755 (executable)
index 0000000..4ad7ba5
--- /dev/null
@@ -0,0 +1,133 @@
+#!/usr/bin/perl
+# vim: et ts=4 sw=4
+# Copyright 2000-2002 Katipo Communications
+#
+# 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::Output;
+use C4::Auth;
+use C4::Koha;
+use C4::Branch; # GetBranches
+
+my $input = new CGI;
+my $dbh = C4::Context->dbh;
+
+my $type=$input->param('type');
+my $branch = $input->param('branch');
+$branch="*" unless $branch;
+my $op = $input->param('op');
+
+# my $flagsrequired;
+# $flagsrequired->{circulation}=1;
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/smart-rules.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+if ($op =~ 'delete-(.*)-(.*)') {
+    my $itemtype = $1;
+    my $categorycode = $2;
+    warn "deleting $1 $2 $branch";
+
+    my $sth_Idelete = $dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=?");
+    $sth_Idelete->execute($branch, $categorycode, $itemtype);
+}
+# save the values entered
+if ($op eq 'add') {
+    my $sth_search = $dbh->prepare("SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
+    my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, issuelength, fine, firstremind, chargeperiod) VALUES(?,?,?,?,?,?,?,?)");
+    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, firstremind=?, chargeperiod=?, maxissueqty=?, issuelength=? WHERE branchcode=? AND categorycode=? AND itemtype=?");
+    
+    my $br = $branch; # branch
+    my $bor = $input->param('categorycode'); # borrower category
+    my $cat = $input->param('itemtype'); # item type
+    my $fine = $input->param('fine');
+    my $firstremind = $input->param('firstremind');
+    my $chargeperiod = $input->param('chargeperiod');
+    my $maxissueqty = $input->param('maxissueqty');
+    my $issuelength = $input->param('issuelength');
+    warn "Adding $br, $bor, $cat, $fine, $maxissueqty";
+
+    $sth_search->execute($br,$bor,$cat);
+    my $res = $sth_search->fetchrow_hashref();
+    if ($res->{total}) {
+        $sth_update->execute($fine, $firstremind, $chargeperiod, $maxissueqty,$issuelength,$br,$bor,$cat);
+    } else {
+        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$issuelength,$fine,$firstremind,$chargeperiod);
+    }
+}
+my $branches = GetBranches();
+my @branchloop;
+foreach my $thisbranch (keys %$branches) {
+    my $selected = 1 if $thisbranch eq $branch;
+    my %row =(value => $thisbranch,
+                selected => $selected,
+                branchname => $branches->{$thisbranch}->{'branchname'},
+            );
+    push @branchloop, \%row;
+}
+
+my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
+$sth->execute;
+my @category_loop;
+while (my $data=$sth->fetchrow_hashref){
+    push @category_loop,$data;
+}
+
+my %row = (categorycode => "*", description => 'Any');
+push @category_loop, \%row;
+
+$sth->finish;
+$sth=$dbh->prepare("SELECT description,itemtype FROM itemtypes ORDER BY description");
+$sth->execute;
+# $i=0;
+my $toggle= 1;
+my @row_loop;
+my @itemtypes;
+while (my $row=$sth->fetchrow_hashref){
+    push @itemtypes,$row;
+    
+}
+my %row = (itemtype => '*', description => 'Any');
+push @itemtypes,\%row;
+
+my $sth2 = $dbh->prepare("SELECT issuingrules.*, itemtypes.description AS humanitemtype, categories.description AS humancategorycode FROM issuingrules LEFT JOIN itemtypes ON (itemtypes.itemtype = issuingrules.itemtype) LEFT JOIN categories ON (categories.categorycode = issuingrules.categorycode) WHERE issuingrules.branchcode = ?");
+$sth2->execute($branch);
+
+while (my $row = $sth2->fetchrow_hashref) {
+    $row->{'humanitemtype'} ||= $row->{'itemtype'};
+    $row->{'humanitemtype'} = 'Any' if $row->{'humanitemtype'} eq '*';
+    $row->{'humancategorycode'} ||= $row->{'categorycode'};
+    $row->{'humancategorycode'} = 'Any' if $row->{'humancategorycode'} eq '*';
+    $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
+    push @row_loop, $row;
+}
+$sth->finish;
+$template->param(categoryloop => \@category_loop,
+                        itemtypeloop => \@itemtypes,
+                        rules => \@row_loop,
+                        branchloop => \@branchloop,
+                        humanbranch => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''),
+                        branch => $branch
+                        );
+output_html_with_http_headers $input, $cookie, $template->output;
index e34fdc6..708a5d0 100644 (file)
@@ -18,6 +18,7 @@
        <li><a href="/cgi-bin/koha/admin/roadtype.pl">Road types</a></li>
        <li><a href="/cgi-bin/koha/admin/issuingrules.pl">Circulation rules</a></li>
        <li><a href="/cgi-bin/koha/admin/finesrules.pl">Fines rules</a></li>
+       <li><a href="/cgi-bin/koha/admin/smart-rules.pl">Alternate issuing rules</a></li>
 </ul>
 
 <h5>Catalogue</h5>
index d60d951..1e3d370 100644 (file)
@@ -48,6 +48,8 @@
        <dd>Define circulation rules in a matrix for libraries / patrons / itemtypes / circ codes (number of checkouts, duration, fee, etc.).</dd>
        <dt><a href="/cgi-bin/koha/admin/finesrules.pl">Fines rules</a></dt>
        <dd>Define fines in a matrix for libraries / patrons / itemtypes (cost, grace period, etc.).</dd>
+    <dt><a href="/cgi-bin/koha/admin/smart-rules.pl">Circulation and fines rules (alternate layout)</a></dt>
+    <dd>Define circulation rules and fines as a list</dd>
 </dl>
 </div>
 <div class="yui-u">
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl
new file mode 100644 (file)
index 0000000..f732236
--- /dev/null
@@ -0,0 +1,108 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha &rsaquo; Administration &rsaquo; Issuing Rules</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+
+<script type="text/javascript">
+//<![CDATA[
+$(document).ready(function() {
+        $('#selectlibrary').find("input:submit").hide();
+        $('#branch').change(function() {
+                $('#selectlibrary').submit();
+        });
+});
+//]]>
+</script>
+
+</head>
+<body>
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;  Issuing Rules</div>
+
+<div id="doc3" class="yui-t1">
+
+<div id="bd">
+    <div id="yui-main">
+    <div class="yui-b">
+    <h1 class="parameters">
+        <!-- TMPL_IF NAME="humanbranch" -->
+            Defining issuing rules for "<!-- TMPL_VAR NAME="humanbranch" -->"
+        <!-- TMPL_ELSE -->
+            Defining default issuing rules
+        <!-- /TMPL_ELSE --><!-- /TMPL_IF -->
+    </h1>
+    <div class="help">
+        <p>The rules are applied from most specific to less specific, using the first found in this order:</p>
+        <ul>
+            <li>same branch, same borrower type, same item type</li>
+            <li>same branch, same borrower type, default item type</li>
+            <li>same branch, default borrower type, same item type</li>
+            <li>default branch, same borrower type, same item type</li>
+            <li>anything else</li>
+        </ul>
+        <p>To modify a rule, create a new one with the same borrower type and item type.</p>
+    </div>
+    <div id="bloc100">
+        <form method="GET" id="selectlibrary">
+        Select a branch :
+            <select name="branch" id="branch">
+                <option value="">Default</option>
+            <!-- TMPL_LOOP NAME="branchloop" -->
+                <option value="<!-- TMPL_VAR NAME="value" -->" <!-- TMPL_IF NAME="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR NAME="branchname" --></option>
+            <!-- /TMPL_LOOP -->
+            </select>
+        </form>
+        <form method="post">
+            <input type="hidden" name="op" value="add">
+            <table>
+            <tr>
+                <th>Item Type</th><th>Borrower Type</th><th>Amount</th><th>Grace Period</th><th>Charging Interval</th><th>Amount Loanable</th><th>Loan time</th>
+            </tr>
+            <!-- TMPL_LOOP NAME="rules" -->
+                <tr>
+                    <td><!-- TMPL_VAR NAME="humanitemtype" --></td>
+                    <td><!-- TMPL_VAR NAME="humancategorycode" --></td>
+                    <td>$<!-- TMPL_VAR NAME="fine" --></td>
+                    <td><!-- TMPL_VAR NAME="firstremind" --> day(s)</td>
+                    <td><!-- TMPL_VAR NAME="chargeperiod" --> day(s)</td>
+                    <td><!-- TMPL_VAR NAME="maxissueqty" --></td>
+                    <td><!-- TMPL_VAR NAME="issuelength" --> day(s)</td>
+                    <td>
+                        <a class="button" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-<!-- TMPL_VAR NAME="itemtype" -->-<!-- TMPL_VAR NAME="categorycode" -->&amp;branch=<!-- TMPL_VAR NAME="branch" -->">Delete</a>
+                    </td>
+                </tr>
+            <!-- /TMPL_LOOP -->
+                <tr>
+                    <td>
+                        <select name="itemtype">
+                        <!-- TMPL_LOOP NAME="itemtypeloop" -->
+                            <option value="<!-- TMPL_VAR NAME="itemtype" -->"><!-- TMPL_VAR NAME="description" --></option>
+                        <!-- /TMPL_LOOP -->
+                        </select>
+                    </td>
+                    <td>
+                        <select name="categorycode">
+                        <!-- TMPL_LOOP NAME="categoryloop" -->
+                            <option value="<!-- TMPL_VAR NAME="categorycode" -->"><!-- TMPL_VAR NAME="description" --></option>
+                        <!-- /TMPL_LOOP -->
+                        </select>
+                    </td>
+                    <td>$<input name="fine" size="4" /></td>
+                    <td><input name="firstremind" size="2" /> day(s)</td>
+                    <td><input name="chargeperiod" size="2" /> day(s)</td>
+                    <td><input name="maxissueqty" size="3" /></td>
+                    <td><input name="issuelength" size="3" /> day(s)</td>
+                    <td><input type="hidden" name="branch" value="<!-- TMPL_VAR NAME="branch" -->"/><input type="submit" value="Add" class="submit" /></td>
+                </tr>
+            </table>
+        </form>
+    </div>
+</div>
+
+</div>
+<div class="yui-b">
+<!-- TMPL_INCLUDE NAME="admin-menu.inc" -->
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->