koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/admin admin-careers.pl admin-home.pl aqboo... [rel_TG]


From: Tumer Garip
Subject: [Koha-cvs] koha/admin admin-careers.pl admin-home.pl aqboo... [rel_TG]
Date: Sun, 25 Mar 2007 23:14:18 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         rel_TG
Changes by:     Tumer Garip <tgarip1957>        07/03/25 23:14:18

Added files:
        admin          : admin-careers.pl admin-home.pl aqbookfund.pl 
                         aqbudget.pl auth_subfields_structure.pl 
                         auth_tag_structure.pl authorised_values.pl 
                         authtypes.pl biblios_framework.pl 
                         biblios_subfields_structure.pl 
                         bibliostagstructure.pl branches.pl categorie.pl 
                         categoryitem.pl checkmarc.pl currency.pl 
                         facets_labels.pl 
                         holdings_subfields_structure.pl 
                         holdingstagstructure.pl institutions-careers.pl 
                         issuingrules.pl itemtypes.pl koha-electronic.pl 
                         koha_attr.pl onlinedatabases.pl printers.pl 
                         systempreferences.pl thesaurus.pl viewlog.pl 
                         z3950servers.pl 

Log message:
        Recommitting everything

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/admin/admin-careers.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/admin/admin-home.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.4.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/aqbookfund.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.32.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/aqbudget.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.24.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/auth_subfields_structure.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.9.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/auth_tag_structure.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.7.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/authorised_values.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.18.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/authtypes.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.6.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/biblios_framework.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/biblios_subfields_structure.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/bibliostagstructure.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/branches.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.37.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/categorie.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.24.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/categoryitem.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.12.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/checkmarc.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.10.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/currency.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.14.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/facets_labels.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/admin/holdings_subfields_structure.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/holdingstagstructure.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/institutions-careers.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/issuingrules.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.11.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/itemtypes.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.25.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/koha-electronic.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.2.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/koha_attr.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.3.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/onlinedatabases.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/admin/printers.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.14.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/systempreferences.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.36.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/thesaurus.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.14.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/viewlog.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.4.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/z3950servers.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.14.2.2

Patches:
Index: admin-careers.pl
===================================================================
RCS file: admin-careers.pl
diff -N admin-careers.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ admin-careers.pl    25 Mar 2007 23:14:17 -0000      1.1.2.1
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+
+# Script to manage the educational institutions and its careers.
+# written 12/04
+# CastaƱeda, Carlos Sebastian - address@hidden - Physics Library UNLP Argentina
+
+# 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::Auth;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::AcademicInfo;
+
+
+my $cgi = new CGI;
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/admin-careers.tmpl",
+                            query => $cgi,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {editcatalogue => 1},
+                            debug => 1,
+                            });
+
+my $op = $cgi->param('op'); 
+my $id_career = $cgi->param('id_career'); 
+my $id_institution = $cgi->param('id_institution');
+my $career_name = $cgi->param('career_name'); 
+
+if ($op eq 'add_form') {
+
+       if ($id_career) {
+               my $info = &get_career($id_career);
+               $template->param(op => 'edit');
+               $template->param(career_name => $info->{'career_name'});
+               $template->param(id_career => $id_career);
+       } else {
+               $template->param(op => 'add');
+               $template->param(add => 1);
+       }
+       my $info = &get_educational_institution($id_institution);
+       $template->param(id_institution => $id_institution);
+       $template->param(institution_name => $info->{'institution_name'});
+
+} elsif ($op eq 'add') {
+       add_career($id_institution, $career_name);
+       print $cgi->redirect('/cgi-bin/koha/admin/institutions-careers.pl');
+} elsif ($op eq 'edit') {
+       update_career($id_career, $career_name);
+       print $cgi->redirect('/cgi-bin/koha/admin/institutions-careers.pl');
+} elsif ($op eq 'del') {
+       warn "enter $id_career";
+       del_career($id_career);
+       print $cgi->redirect('/cgi-bin/koha/admin/institutions-careers.pl');
+}
+
+output_html_with_http_headers $cgi, $cookie, $template->output;

Index: admin-home.pl
===================================================================
RCS file: admin-home.pl
diff -N admin-home.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ admin-home.pl       25 Mar 2007 23:14:17 -0000      1.4.2.2
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+
+my $query = new CGI;
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/admin-home.tmpl",
+                            query => $query,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1, management => 
1, tools => 1},
+                            debug => 1,
+                            });
+
+output_html_with_http_headers $query, $cookie, $template->output;

Index: aqbookfund.pl
===================================================================
RCS file: aqbookfund.pl
diff -N aqbookfund.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ aqbookfund.pl       25 Mar 2007 23:14:17 -0000      1.32.2.2
@@ -0,0 +1,286 @@
+#!/usr/bin/perl
+
+#written 20/02/2002 by address@hidden
+
+# 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
+
+
+=head1 NAME
+
+aqbookfund.pl
+
+=head1 DESCRIPTION
+
+script to administer the aqbudget table.
+
+=head1 CGI PARAMETERS
+
+=over 4
+
+=item op
+this script use an C<$op> to know what to do.
+C<op> can be equal to:
+* empty or none of the above values, then
+    - the default screen is build (with all records, or filtered datas).
+       - the   user can clic on add, modify or delete record.
+* add_form, then
+       - if primkey exists, this is a modification,so we read the $primkey 
record
+       - builds the add/modify form
+* add_validate, then
+       - the user has just send datas, so we create/modify the record
+* delete_form, then
+       - we show the record having primkey=$primkey and ask for deletion 
validation form
+* delete_confirm, then
+    - we delete the record having primkey=$primkey
+
+=cut
+
+use strict;
+use CGI;
+use C4::Output;
+use List::Util qw/min/;
+use C4::Auth;
+use C4::Koha;
+use C4::Context;
+use C4::Bookfund;
+use C4::Interface::CGI::Output;
+use C4::Search;
+use C4::Date;
+
+my $dbh = C4::Context->dbh;
+my $input = new CGI;
+my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
+my $bookfundid=$input->param('bookfundid');
+my $pagesize = 10;
+my $op = $input->param('op') || '';
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user(
+        {template_name => "admin/aqbookfund.tmpl",
+         query => $input,
+         type => "intranet",
+         authnotrequired => 0,
+         flagsrequired => {parameters => 1, management => 1},
+         debug => 1,
+        }
+    );
+
+if ($op) {
+    $template->param(
+        script_name => $script_name,
+        $op => 1,
+    ); # we show only the TMPL_VAR names $op
+}
+else {
+    $template->param(script_name => $script_name,
+               else              => 1); # we show only the TMPL_VAR names $op
+}
+$template->param(action => $script_name);
+
+my $branches = GetBranches;
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $dataaqbookfund;
+       my $header;
+       if ($bookfundid) {
+       $dataaqbookfund = GetBookFund($bookfundid);
+       }
+       if ($bookfundid) {
+           $header = "Modify book fund";
+           $template->param('header-is-modify-p' => 1);
+       } else {
+           $header = "Add book fund";
+           $template->param('header-is-add-p' => 1);
+       }
+       $template->param('use-header-flags-p' => 1);
+       $template->param(header => $header); 
+       my $add_or_modify=0;
+       if ($bookfundid) {
+           $add_or_modify=1;
+       }
+       $template->param(add_or_modify => $add_or_modify);
+       $template->param(bookfundid =>$bookfundid);
+       $template->param(bookfundname =>$dataaqbookfund->{'bookfundname'});
+warn $dataaqbookfund->{'bookfundname'};
+        my @branchloop;
+        foreach my $branchcode (sort keys %{$branches}) {
+            my $row = {
+                branchcode => $branchcode,
+                branchname => $branches->{$branchcode}->{branchname},
+            };
+
+            if ( $bookfundid    && $dataaqbookfund->{branchcode} eq 
$branchcode) {
+                $row->{selected} = 1;
+            }
+
+            push @branchloop, $row;
+        }
+
+        $template->param(branches => address@hidden);
+
+} # END $OP eq ADD_FORM
+
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+elsif ($op eq 'add_validate') {
+       my $bookfundid = uc $input->param('bookfundid');
+
+    my $number = Countbookfund($bookfundid);
+
+    my $bookfund_already_exists = $number > 0 ? 1 : 0;
+
+    if ($bookfund_already_exists) {
+        my $bookfundname = $input->param('bookfundname');
+        my $branchcode = $input->param('branchcode') || undef;
+
+        ModBookFund($bookfundname,$branchcode,$bookfundid);
+    }
+    else {
+        NewBookFund(
+            $bookfundid,
+            $input->param('bookfundname'),
+            $input->param('branchcode')
+        );
+    }
+    $input->redirect('aqbookfund.pl');
+# END $OP eq ADD_VALIDATE
+}
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+
+elsif ($op eq 'delete_confirm') {
+    my $data = GetBookFund($bookfundid);
+       $template->param(bookfundid => $bookfundid);
+       $template->param(bookfundname => $data->{'bookfundname'});
+} # END $OP eq DELETE_CONFIRM
+
+
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+elsif ($op eq 'delete_confirmed') {
+    DelBookFund(uc($input->param('bookfundid')));
+
+}# END $OP eq DELETE_CONFIRMED
+
+
+################## DEFAULT ##################################
+else { # DEFAULT
+    my ($query, $sth);
+
+    $template->param(scriptname => $script_name);
+
+    # filters
+    my @branchloop;
+    foreach my $branchcode (sort keys %{$branches}) {
+        my $row = {
+            code => $branchcode,
+            name => $branches->{$branchcode}->{branchname},
+        };
+
+        if (defined $input->param('filter_branchcode')
+            and $input->param('filter_branchcode') eq $branchcode) {
+            $row->{selected} = 1;
+        }
+
+        push @branchloop, $row;
+    }
+
+    my @bookfundids_loop;
+    my $sth = GetBookFundsId();
+
+    while (my $row = $sth->fetchrow_hashref) {
+        if (defined $input->param('filter_bookfundid') and 
$input->param('filter_bookfundid') eq $row->{bookfundid}){
+            $row->{selected} = 1;
+        }
+         push @bookfundids_loop, $row;
+     }
+
+    $template->param(
+        filter_bookfundids => address@hidden,
+        filter_branches => address@hidden,
+        filter_bookfundname => $input->param('filter_bookfundname') || undef,
+    );
+
+    # searching the bookfunds corresponding to our filtering rules
+    my @results = SearchBookFund(
+        $input->param('filter'),
+        $input->param('filter_bookfundid'),
+        $input->param('filter_bookfundname'),
+        $input->param('filter_branchcode'),
+    );
+
+    # does the book funds have budgets?
+    my @loop_id;
+    my $sth = GetBookFundsId();
+    while (my $row = $sth->fetchrow){
+        push @loop_id, $row;
+    }
+
+    my ($id,%nb_budgets_of);
+    foreach $id (@loop_id){
+        my $number = Countbookfund($id);
+        $nb_budgets_of{$id} = $number;
+    }
+
+    # pagination informations
+    my $page = $input->param('page') || 1;
+    my @loop;
+
+    my $first = ($page - 1) * $pagesize;
+
+    # if we are on the last page, the number of the last word to display
+    # must not exceed the length of the results array
+    my $last = min(
+        $first + $pagesize - 1,
+        scalar(@results) - 1,
+    );
+
+    my $toggle = 0;
+    foreach my $result (@results[$first .. $last]) {
+        push(
+            @loop,
+            {
+                %{$result},
+                toggle => $toggle++%2,
+                branchname =>
+                    $branches->{ $result->{branchcode} }->{branchname},
+                has_budgets => defined $nb_budgets_of{ $result->{bookfundid} },
+            }
+        );
+    }
+
+    $template->param(
+            bookfund => address@hidden,
+            pagination_bar => pagination_bar(
+                        $script_name,
+                        getnbpages(scalar @results, $pagesize),
+                        $page,
+                        'page'
+            )
+        );
+} #---- END $OP eq DEFAULT
+$template->param(
+    intranetcolorstylesheet 
=>C4::Context->preference("intranetcolorstylesheet"),
+    intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+    IntranetNav => C4::Context->preference("IntranetNav"),
+    );
+
+output_html_with_http_headers $input, $cookie, $template->output;

Index: aqbudget.pl
===================================================================
RCS file: aqbudget.pl
diff -N aqbudget.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ aqbudget.pl 25 Mar 2007 23:14:17 -0000      1.24.2.2
@@ -0,0 +1,431 @@
+#!/usr/bin/perl
+
+#script to administer the aqbudget table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+
+# 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 List::Util qw/min/;
+use C4::Date;
+use C4::Auth;
+use C4::Acquisition;
+use C4::Context;
+use C4::Interface::CGI::Output;
+use C4::Search;
+use C4::Koha;
+use C4::Output;
+
+my $input = new CGI;
+my $script_name="/cgi-bin/koha/admin/aqbudget.pl";
+my $bookfundid=$input->param('bookfundid');
+my $aqbudgetid=$input->param('aqbudgetid');
+my $pagesize = 20;
+my $op = $input->param('op');
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user(
+        {template_name => "admin/aqbudget.tmpl",
+         query => $input,
+         type => "intranet",
+         authnotrequired => 0,
+         flagsrequired => {parameters => 1},
+         debug => 1,
+     }
+    );
+
+$template->param(
+    action => $script_name,
+    DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+    script_name => $script_name,
+    $op || 'else' => 1,
+);
+
+my $dbh = C4::Context->dbh;
+my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where 
borrowernumber = ?");
+$sthtemp->execute($borrowernumber);
+my ($flags, $homebranch)=$sthtemp->fetchrow;
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+    my ($query, $dataaqbudget, $dataaqbookfund, $sth);
+    my $dbh = C4::Context->dbh;
+
+    #---- if primkey exists, it's a modify action, so read values to modify...
+    if ($aqbudgetid) {
+        $query = '
+SELECT aqbudgetid,
+       bookfundname,
+       aqbookfund.bookfundid,
+       startdate,
+       enddate,
+       budgetamount,
+       aqbudget.branchcode
+  FROM aqbudget
+    INNER JOIN aqbookfund ON aqbudget.bookfundid = aqbookfund.bookfundid
+  WHERE aqbudgetid = ?
+';
+        $sth=$dbh->prepare($query);
+        $sth->execute($aqbudgetid);
+        $dataaqbudget=$sth->fetchrow_hashref;
+        $sth->finish;
+    }
+
+    $query = '
+SELECT aqbookfund.branchcode,
+       branches.branchname,
+       aqbookfund.bookfundname
+  FROM aqbookfund
+    LEFT JOIN branches ON aqbookfund.branchcode = branches.branchcode
+  WHERE bookfundid = ?
+';
+    $sth=$dbh->prepare($query);
+    $sth->execute(
+        defined $aqbudgetid ? $dataaqbudget->{bookfundid} : $bookfundid,
+    );
+    $dataaqbookfund=$sth->fetchrow_hashref;
+    $sth->finish;
+
+    if (defined $aqbudgetid) {
+        $template->param(
+            bookfundid => $dataaqbudget->{'bookfundid'},
+            bookfundname => $dataaqbudget->{'bookfundname'}
+        );
+    }
+    else {
+        $template->param(
+            bookfundid => $bookfundid,
+            bookfundname => $dataaqbookfund->{bookfundname},
+        );
+    }
+
+    # Available branches
+    my @branches = ();
+
+    $query = '
+SELECT branchcode,
+       branchname
+  FROM branches
+  ORDER BY branchname
+';
+    $sth=$dbh->prepare($query);
+    $sth->execute();
+    while (my $row = $sth->fetchrow_hashref) {
+        my $branch = $row;
+
+        if (defined $dataaqbookfund->{branchcode}) {
+            $branch->{selected} =
+                $dataaqbookfund->{branchcode} eq $row->{branchcode} ? 1 : 0;
+        }
+        elsif (defined $aqbudgetid) {
+            $branch->{selected} =
+                $dataaqbudget->{branchcode} eq $row->{branchcode} ? 1 : 0;
+        }
+
+        push @branches, $branch;
+    }
+    $sth->finish;
+
+    $template->param(
+        dateformat => display_date_format(),
+        aqbudgetid => $dataaqbudget->{'aqbudgetid'},
+        startdate => format_date($dataaqbudget->{'startdate'}),
+        enddate => format_date($dataaqbudget->{'enddate'}),
+        budgetamount => $dataaqbudget->{'budgetamount'},
+        branches => address@hidden,
+    );
+
+    if (defined $dataaqbookfund->{branchcode}) {
+        $template->param(
+            disable_branchselection => 1,
+            branch => $dataaqbookfund->{branchcode},
+        );
+    }
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+    my ($query, $sth);
+
+    if (defined $aqbudgetid) {
+        $query = '
+UPDATE aqbudget
+  SET bookfundid = ?,
+      startdate = ?,
+      enddate = ?,
+      budgetamount = ?,
+      branchcode = ?
+  WHERE aqbudgetid = ?
+';
+        $sth=$dbh->prepare($query);
+        $sth->execute(
+            $input->param('bookfundid'),
+            format_date_in_iso($input->param('startdate')),
+            format_date_in_iso($input->param('enddate')),
+            $input->param('budgetamount'),
+            $input->param('branch') || undef,
+            $aqbudgetid,
+        );
+        $sth->finish;
+    }
+    else {
+        $query = '
+INSERT
+  INTO aqbudget
+  (bookfundid, startdate, enddate, budgetamount, branchcode)
+  VALUES
+  (?, ?, ?, ?, ?)
+';
+        $sth=$dbh->prepare($query);
+        $sth->execute(
+            $input->param('bookfundid'),
+            format_date_in_iso($input->param('startdate')),
+            format_date_in_iso($input->param('enddate')),
+            $input->param('budgetamount'),
+            $input->param('branch') || undef,
+        );
+        $sth->finish;
+    }
+
+    $input->redirect("aqbudget.pl");
+
+# END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select 
aqbudgetid,bookfundid,startdate,enddate,budgetamount,branchcode from aqbudget 
where aqbudgetid=?");
+       $sth->execute($aqbudgetid);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(bookfundid => $bookfundid);
+       $template->param(aqbudgetid => $data->{'aqbudgetid'});
+       $template->param(startdate => format_date($data->{'startdate'}));
+       $template->param(enddate => format_date($data->{'enddate'}));
+       $template->param(budgetamount => $data->{'budgetamount'});
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       my $dbh = C4::Context->dbh;
+       my $aqbudgetid=uc($input->param('aqbudgetid'));
+       my $sth=$dbh->prepare("delete from aqbudget where aqbudgetid=?");
+       $sth->execute($aqbudgetid);
+       $sth->finish;
+        print $input->redirect("aqbookfund.pl");
+        return;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+    my ($query, $sth);
+
+    # create a look-up table for bookfund names from bookfund ids,
+    # instead of having on query per budget
+    my %bookfundname_of = ();
+    $query = '
+SELECT bookfundid, bookfundname
+  FROM aqbookfund
+';
+    $sth=$dbh->prepare($query);
+    $sth->execute;
+    while (my $row = $sth->fetchrow_hashref) {
+        $bookfundname_of{ $row->{bookfundid} } = $row->{bookfundname};
+    }
+    $sth->finish;
+
+    # filters
+    my $branches = GetBranches();
+    my @branchloop;
+    foreach my $branchcode (sort keys %{$branches}) {
+        my $row = {
+            code => $branchcode,
+            name => $branches->{$branchcode}->{branchname},
+        };
+
+        if (defined $input->param('filter_branchcode')
+            and $input->param('filter_branchcode') eq $branchcode) {
+            $row->{selected} = 1;
+        }
+
+        push @branchloop, $row;
+    }
+
+    my @bookfundids_loop;
+    $query = '
+SELECT bookfundid
+  FROM aqbookfund
+';
+    $sth = $dbh->prepare($query);
+    $sth->execute();
+    while (my $row = $sth->fetchrow_hashref) {
+        if (defined $input->param('filter_bookfundid')
+            and $input->param('filter_bookfundid') eq $row->{bookfundid}) {
+            $row->{selected} = 1;
+        }
+
+        push @bookfundids_loop, $row;
+    }
+    $sth->finish;
+
+    $template->param(
+        filter_bookfundids => address@hidden,
+        filter_branches => address@hidden,
+        filter_amount => $input->param('filter_amount') || undef,
+        filter_startdate => $input->param('filter_startdate') || undef,
+        filter_enddate => $input->param('filter_enddate') || undef,
+    );
+
+    my %sign_label_of = (
+        '=' => 'equal',
+        '>=' => 'superior',
+        '<=' => 'inferior',
+    );
+
+    foreach my $field (qw/startdate enddate amount/) {
+        my $param = 'filter_'.$field.'_sign';
+
+        foreach my $sign (keys %sign_label_of) {
+            if ($input->param($param) eq $sign) {
+                $template->param(
+                    $param.'_'.$sign_label_of{$sign}.'_selected' => 1,
+                );
+            }
+        }
+    }
+
+    # Search all available budgets
+    $query = '
+SELECT aqbudgetid,
+       bookfundid,
+       startdate,
+       enddate,
+       budgetamount,
+       branchcode
+  FROM aqbudget
+  WHERE 1 = 1';
+
+    my @bindings;
+
+    if ($input->param('filter_bookfundid')) {
+        $query.= '
+    AND bookfundid = ?
+';
+        push @bindings, $input->param('filter_bookfundid');
+    }
+    if ($input->param('filter_branchcode')) {
+        $query.= '
+    AND branchcode = ?
+';
+        push @bindings, $input->param('filter_branchcode');
+    }
+    if ($input->param('filter_startdate')) {
+        $query.= '
+    AND startdate '.$input->param('filter_startdate_sign').' ?
+';
+        push @bindings, format_date_in_iso($input->param('filter_startdate'));
+    }
+    if ($input->param('filter_enddate')) {
+        $query.= '
+    AND enddate '.$input->param('filter_enddate_sign').' ?
+';
+        push @bindings, format_date_in_iso($input->param('filter_enddate'));
+    }
+    if ($input->param('filter_amount')) {
+        $query.= '
+    AND budgetamount '.$input->param('filter_amount_sign').' ?
+';
+        # the amount must be a quantity, with 2 digits after the decimal
+        # separator
+        $input->param('filter_amount') =~ m{(\d* (?:\.\d{,2})? )}xms;
+        my ($amount) = $1;
+        push @bindings, $amount;
+    }
+
+    $query.= '
+  ORDER BY bookfundid, aqbudgetid
+';
+    $sth = $dbh->prepare($query);
+    $sth->execute(@bindings);
+    my @results;
+    while (my $row = $sth->fetchrow_hashref){
+        push @results, $row;
+    }
+    $sth->finish;
+
+    # filter budgets depending on the pagination
+    my $page = $input->param('page') || 1;
+    my $first = ($page - 1) * $pagesize;
+
+    # if we are on the last page, the number of the last word to display
+    # must not exceed the length of the results array
+    my $last = min(
+        $first + $pagesize - 1,
+        scalar @results - 1,
+    );
+
+    my $toggle = 0;
+    my @loop;
+    foreach my $result (@results[$first .. $last]) {
+        push(
+            @loop,
+            {
+                %{$result},
+                toggle => $toggle++%2,
+                bookfundname => $bookfundname_of{ $result->{'bookfundid'} },
+                branchname => $branches->{ $result->{branchcode} 
}->{branchname},
+                startdate => format_date($result->{startdate}),
+                enddate => format_date($result->{enddate}),
+            }
+        );
+    }
+
+    $template->param(
+        budget => address@hidden,
+        pagination_bar => pagination_bar(
+            $script_name,
+            getnbpages(scalar @results, $pagesize),
+            $page,
+            'page'
+        )
+    );
+} #---- END $OP eq DEFAULT
+$template->param(intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;
+

Index: auth_subfields_structure.pl
===================================================================
RCS file: auth_subfields_structure.pl
diff -N auth_subfields_structure.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ auth_subfields_structure.pl 25 Mar 2007 23:14:17 -0000      1.9.2.2
@@ -0,0 +1,451 @@
+#!/usr/bin/perl
+
+
+# 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 C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Auth;
+use CGI;
+use C4::Search;
+use C4::Context;
+
+
+sub StringSearch  {
+       my ($env,$searchstring,$authtypecode)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from auth_subfield_structure where 
(tagfield like ? and authtypecode=?) order by tagfield");
+       $sth->execute("$searchstring%",$authtypecode);
+       my @results;
+       my $cnt=0;
+       my $u=1;
+       while (my $data=$sth->fetchrow_hashref){
+               push(@results,$data);
+               $cnt ++;
+               $u++;
+       }
+       $sth->finish;
+       $dbh->disconnect;
+       return ($cnt,address@hidden);
+}
+
+my $input = new CGI;
+my $tagfield=$input->param('tagfield');
+my $tagsubfield=$input->param('tagsubfield');
+my $authtypecode=$input->param('authtypecode');
+my $pkfield="tagfield";
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/auth_subfields_structure.pl";
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => 
"admin/auth_subfields_structure.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+my $pagesize=30;
+my $op = $input->param('op');
+$tagfield=~ s/\,//g;
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               tagfield =>$tagfield,
+                                               authtypecode => $authtypecode,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               tagfield =>$tagfield,
+                                               authtypecode => $authtypecode,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       my $data;
+       my $dbh = C4::Context->dbh;
+       my $more_subfields = $input->param("more_subfields")+1;
+       
+       # build authorised value list
+
+my     $sth2 = $dbh->prepare("select distinct category from 
authorised_values");
+       $sth2->execute;
+       my @authorised_values;
+       push @authorised_values,"";
+       while ((my $category) = $sth2->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       push (@authorised_values,"branches");
+       push (@authorised_values,"itemtypes");
+
+       # build value_builder list
+       my @value_builder=('');
+
+       # read value_builder directory.
+       # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
+       # on a standard install, /cgi-bin need to be added. 
+       # test one, then the other
+       my $cgidir = C4::Context->intranetdir ."/cgi-bin";
+       unless (opendir(DIR, "$cgidir/value_builder")) {
+               $cgidir = C4::Context->intranetdir;
+               opendir(DIR, "$cgidir/value_builder") || die "can't opendir 
$cgidir/value_builder: $!";
+       } 
+       while (my $line = readdir(DIR)) {
+               if ($line =~ /\.pl$/) {
+                       push (@value_builder,$line);
+               }
+       }
+       closedir DIR;
+
+       # build values list
+       my $sth=$dbh->prepare("select * from auth_subfield_structure where 
tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
+       $sth->execute($tagfield,$authtypecode);
+       my @loop_data = ();
+       my $toggle=1;
+       my $i=0;
+       while ($data =$sth->fetchrow_hashref) {
+
+               my %row_data;  # get a fresh hash for the row data
+               if ($toggle eq 1){
+                       $toggle=0;
+               } else {
+                       $toggle=1;
+               }
+               $row_data{tab} = CGI::scrolling_list(-name=>'tab',
+                                       -id=>"tab$i",
+                                       
-values=>['-1','0','1','2','3','4','5','6','7','8','9'],
+                                       -labels => {'-1' 
=>'ignore','0'=>'0','1'=>'1','2' =>'2','3'=>'3','4'=>'4',
+                                                                       '5' 
=>'5','6'=>'6','7'=>'7',
+                                                                       '8' 
=>'8','9'=>'9',},
+                                       -default=>$data->{'tab'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
+                                       -id=>"ohidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>substr($data->{'hidden'},0,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
+                                       -id=>"ihidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>substr($data->{'hidden'},1,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
+                                       -id=>"ehidden$i",
+                                       -values=>['0','1','2'],
+                                       -labels => {'0'=>'Show','1'=>'Show 
Collapsed',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>substr($data->{'hidden'},2,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{tagsubfield} =$data->{'tagsubfield'}."<input 
type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" 
id=\"tagsubfield\">";
+               $row_data{liblibrarian} = 
CGI::escapeHTML($data->{'liblibrarian'});
+               $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
+               $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
+               $row_data{authorised_value}  = 
CGI::scrolling_list(-name=>'authorised_value',
+                                       -id=>'authorised_value',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'authorised_value'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{value_builder}  = 
CGI::scrolling_list(-name=>'value_builder',
+                                       -id=>'value_builder',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'value_builder'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               
+               $row_data{repeatable} = CGI::checkbox(-name=>"repeatable$i",
+       -checked => $data->{'repeatable'}?'checked':'',
+       -value => 1,
+       -label => '',
+       -id => "repeatable$i");
+               $row_data{mandatory} = CGI::checkbox(-name => "mandatory$i",
+       -checked => $data->{'mandatory'}?'checked':'',
+       -value => 1,
+       -label => '',
+       -id => "mandatory$i");
+               $row_data{hidden} = CGI::escapeHTML($data->{hidden}) ;
+               $row_data{isurl} = CGI::checkbox( -name => "isurl$i",
+                       -id => "isurl$i",
+                       -checked => $data->{'isurl'}?'checked':'',
+                       -value => 1,
+                       -label => '');
+               $row_data{link} = CGI::checkbox( -name => "link$i",
+                       -id => "link$i",
+                       -checked => $data->{'link'}?'checked':'',
+                       -value => 1,
+                       -label => '');
+               $row_data{row} = $i;
+               $row_data{toggle} = $toggle;
+               # $row_data{link} = CGI::escapeHTML($data->{'link'});
+               push(@loop_data, \%row_data);
+               $i++;
+       }
+       # add more_subfields empty lines for add if needed
+       for (my $i=1;$i<=$more_subfields;$i++) {
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{tab} = CGI::scrolling_list(-name=>'tab',
+                                       -id=>"tab$i",
+                                       
-values=>['-1','0','1','2','3','4','5','6','7','8','9'],
+                                       -labels => {'-1' 
=>'ignore','0'=>'0','1'=>'1','2' =>'2','3'=>'3','4'=>'4',
+                                                                       '5' 
=>'5','6'=>'6','7'=>'7',
+                                                                       '8' 
=>'8','9'=>'9',},
+                                       -default=>"",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
+                                       -id=>"ohidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+
+               $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
+                                       -id=>"ihidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
+                                       -id=>"ehidden$i",
+                                       -values=>['0','1','2'],
+                                       -labels => {'0'=>'Show','1'=>'Show 
Collapsed',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{tagsubfield} = "<input type=\"text\" 
name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" 
id=\"tagsubfield\" maxlength=\"1\">";
+               $row_data{liblibrarian} = "";
+               $row_data{libopac} = "";
+               $row_data{seealso} = "";
+               $row_data{hidden} = "000";
+               $row_data{repeatable} = CGI::checkbox( -name=> 'repeatable',
+                               -id => "repeatable$i",
+                               -checked => '',
+                               -value => 1,
+                               -label => '');
+               $row_data{mandatory} = CGI::checkbox( -name=> 'mandatory',
+                       -id => "mandatory$i",
+                       -checked => '',
+                       -value => 1,
+                       -label => '');
+               $row_data{isurl} = CGI::checkbox(-name => 'isurl',
+                       -id => "isurl$i",
+                       -checked => '',
+                       -value => 1,
+                       -label => '');
+               
+               $row_data{authorised_value}  = 
CGI::scrolling_list(-name=>'authorised_value',
+                                       -id => 'authorised_value',
+                                       -values=> address@hidden,
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{link} = CGI::checkbox( -name => "link",
+                       -id => "link$i",
+                       -checked => '',
+                       -value => 1,
+                       -label => '');
+               # $row_data{link} = CGI::escapeHTML($data->{'link'});
+               $row_data{toggle} = $toggle;
+               $row_data{row} = $i;
+               push(@loop_data, \%row_data);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param('heading-edit-subfields-p' => 1);
+       $template->param(action => "Edit subfields",
+                                                       tagfield => "<input 
type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
+                                                       loop => address@hidden,
+                                                       more_subfields => 
$more_subfields,
+                                                       more_tag => $tagfield);
+
+                                                                               
                # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       $template->param(tagfield => "$input->param('tagfield')");
+       my $sth=$dbh->prepare("replace auth_subfield_structure 
(tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,
 link)
+                                                                       values 
(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+       my @tagsubfield = $input->param('tagsubfield');
+       my @liblibrarian        = $input->param('liblibrarian');
+       my @libopac             = $input->param('libopac');
+       my @tab                         = $input->param('tab');
+       my @seealso             = $input->param('seealso');
+       #my @hidden             = $input->param('hidden');
+       my @hidden;
+       my @ohidden             = $input->param('ohidden');
+       my @ihidden             = $input->param('ihidden');
+       my @ehidden             = $input->param('ehidden');
+       my @authorised_values   = $input->param('authorised_value');
+#      my $authtypecodes       = $input->param('authtypecode');
+       my @value_builder       =$input->param('value_builder');
+       my @link                =$input->param('link');
+       for (my $i=0; $i<= $#tagsubfield ; $i++) {
+               my $tagfield                    =$input->param('tagfield');
+               my $tagsubfield         =$tagsubfield[$i];
+               $tagsubfield="@" unless $tagsubfield ne '';
+               my $liblibrarian                =$liblibrarian[$i];
+               my $libopac                     =$libopac[$i];
+               my $repeatable          =$input->param("repeatable$i")?1:0;
+               my $mandatory           =$input->param("mandatory$i")?1:0;
+
+               my $tab                         =$tab[$i];
+               my $seealso                             =$seealso[$i];
+               my $authorised_value            =$authorised_values[$i];
+#              my $authtypecode                =$authtypecodes;
+               my $value_builder=$value_builder[$i];
+               my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate 
from 3 hiddens;
+               my $isurl = $input->param("isurl$i")?1:0;
+               my $link = $input->param("link$i")?1:0;
+               if ($liblibrarian) {
+                       unless (C4::Context->config('demo') eq 1) {
+                               $sth->execute ($tagfield,
+                                                                       
$tagsubfield,
+                                                                       
$liblibrarian,
+                                                                       
$libopac,
+                                                                       
$repeatable,
+                                                                       
$mandatory,
+                                                                       $tab,
+                                                                       
$seealso,
+                                                                       
$authorised_value,
+                                                                       
$authtypecode,
+                                                                       
$value_builder,
+                                                                       $hidden,
+                                                                       $isurl,
+                                                                       
+
+        $link,
+                                             );
+                       }
+               }
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
+       exit;
+
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select * from auth_subfield_structure where 
tagfield=? and tagsubfield=? and authtypecode=?");
+       #FIXME : called with 2 bind variables when 3 are needed
+       $sth->execute($tagfield,$tagsubfield);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                                                       tagsubfield => 
$data->{'tagsubfield'},
+                                                       delete_link => 
$script_name,
+                                                       tagfield      
=>$tagfield,
+                                                       tagsubfield => 
$tagsubfield,
+                                                       authtypecode => 
$authtypecode,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       my $dbh = C4::Context->dbh;
+       unless (C4::Context->config('demo') eq 1) {
+               my $sth=$dbh->prepare("delete from auth_subfield_structure 
where tagfield=? and tagsubfield=? and authtypecode=?");
+               $sth->execute($tagfield,$tagsubfield,$authtypecode);
+               $sth->finish;
+       }
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
+       exit;
+       $template->param(tagfield => $tagfield);
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       my $env;
+       my ($count,$results)=StringSearch($env,$tagfield,$authtypecode);
+       my $toggle=1;
+       my @loop_data = ();
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               if ($toggle eq 1){
+                       $toggle=0;
+               } else {
+                       $toggle=1;
+               }
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{tagfield} = $results->[$i]{'tagfield'};
+               $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
+               $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
+               $row_data{repeatable} = $results->[$i]{'repeatable'};
+               $row_data{mandatory} = $results->[$i]{'mandatory'};
+               $row_data{tab} = $results->[$i]{'tab'};
+               $row_data{seealso} = $results->[$i]{'seealso'};
+               $row_data{authorised_value} = 
$results->[$i]{'authorised_value'};
+               $row_data{authtypecode} = $results->[$i]{'authtypecode'};
+               $row_data{value_builder}        = 
$results->[$i]{'value_builder'};
+               $row_data{hidden}       = $results->[$i]{'hidden'} 
if($results->[$i]{'hidden'} gt "000") ;
+               $row_data{isurl}        = $results->[$i]{'isurl'};
+               $row_data{link} = $results->[$i]{'link'};
+               $row_data{delete} = 
"$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
+               $row_data{toggle} = $toggle;
+               if ($row_data{tab} eq -1) {
+                       $row_data{subfield_ignored} = 1;
+               }
+
+               push(@loop_data, \%row_data);
+       }
+       $template->param(loop => address@hidden);
+       $template->param(edit_tagfield => $tagfield,
+               edit_authtypecode => $authtypecode);
+       
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(prev =>"<a 
href=\"$script_name?offset=$prevpage\">");
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(next => "<a 
href=\"$script_name?offset=$nextpage\">");
+       }
+} #---- END $OP eq DEFAULT
+$template->param(intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;

Index: auth_tag_structure.pl
===================================================================
RCS file: auth_tag_structure.pl
diff -N auth_tag_structure.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ auth_tag_structure.pl       25 Mar 2007 23:14:17 -0000      1.7.2.2
@@ -0,0 +1,297 @@
+#!/usr/bin/perl
+
+
+# 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::Auth;
+use C4::Koha;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+use C4::Context;
+
+
+# retrieve parameters
+my $input = new CGI;
+my $authtypecode = $input->param('authtypecode'); # set to select framework
+$authtypecode="" unless $authtypecode;
+my $existingauthtypecode = $input->param('existingauthtypecode'); # set when 
we have to create a new framework (in authtype) by copying an old one (in 
existingauthtype)
+$existingauthtypecode = "" unless $existingauthtypecode;
+# my $authtypeinfo = getauthtypeinfo($authtype);
+my $searchfield=$input->param('searchfield');
+$searchfield=0 unless $searchfield;
+$searchfield=~ s/\,//g;
+
+my $offset=$input->param('offset');
+my $op = $input->param('op');
+my $pagesize=20;
+
+my $script_name="/cgi-bin/koha/admin/auth_tag_structure.pl";
+
+my $dbh = C4::Context->dbh;
+
+# open template
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/auth_tag_structure.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+# get authtype list
+my $authtypes = getauthtypes;
+my @authtypesloop;
+foreach my $thisauthtype (keys %$authtypes) {
+       my $selected = 1 if $thisauthtype eq $authtypecode;
+       my %row =(value => $thisauthtype,
+                               selected => $selected,
+                               authtypetext => 
$authtypes->{$thisauthtype}->{'authtypetext'},
+                       );
+       push @authtypesloop, \%row;
+}
+
+my $sth;
+# check that authtype framework is defined in auth_tag_structure if we are on 
a default action
+if (!$op or $op eq 'authtype_create_confirm') {
+#warn "IN";
+       $sth=$dbh->prepare("select count(*) from auth_tag_structure where 
authtypecode=?");
+       $sth->execute($authtypecode);
+       my ($authtypeexist) = $sth->fetchrow;
+       if ($authtypeexist) {
+       } else {
+               # if authtype does not exists, then OP must be changed to 
"create authtype" if we are not on the way to create it
+               # (op = authtyp_create_confirm)
+               if ($op eq "authtype_create_confirm") {
+                       duplicate_auth_framework($authtypecode, 
$existingauthtypecode);
+               } else {
+                       $op = "authtype_create";
+               }
+       }
+}
+$template->param(authtypeloop => address@hidden);
+if ($op && $op ne 'authtype_create_confirm') {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               $sth=$dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
auth_tag_structure where tagfield=? and authtypecode=?");
+               $sth->execute($searchfield,$authtypecode);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       my $sth = $dbh->prepare("select distinct category from 
authorised_values");
+       $sth->execute;
+       my @authorised_values;
+       push @authorised_values,"";
+       while ((my $category) = $sth->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       my $authorised_value  = CGI::scrolling_list(-name=>'authorised_value',
+                       -values=> address@hidden,
+                       -size=>1,
+                       -multiple=>0,
+                       -default => $data->{'authorised_value'},
+                       );
+
+       if ($searchfield) {
+               $template->param(action => "Modify tag",
+                                                               searchfield => 
"<input type=\"hidden\" name=\"tagfield\" value=\"$searchfield\" 
/>$searchfield");
+               $template->param('heading-modify-tag-p' => 1);
+       } else {
+               $template->param(action => "Add tag",
+                                                               searchfield => 
"<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
+               $template->param('heading-add-tag-p' => 1);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                                                       libopac => 
$data->{'libopac'},
+                                                       repeatable => 
CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''),
+                                                       mandatory => 
CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''),
+                                                       authorised_value => 
$authorised_value,
+                                                       authtypecode => 
$authtypecode,
+                                                       );
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $sth=$dbh->prepare("replace auth_tag_structure 
(tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,authtypecode)
 values (?,?,?,?,?,?,?)");
+       my $tagfield       =$input->param('tagfield');
+       my $liblibrarian  = $input->param('liblibrarian');
+       my $libopac       =$input->param('libopac');
+       my $repeatable =$input->param('repeatable');
+       my $mandatory =$input->param('mandatory');
+       my $authorised_value =$input->param('authorised_value');
+       unless (C4::Context->config('demo') eq 1) {
+               $sth->execute($tagfield,
+                                               $liblibrarian,
+                                               $libopac,
+                                               $repeatable?1:0,
+                                               $mandatory?1:0,
+                                               $authorised_value,
+                                               $authtypecode
+                                               );
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=auth_tag_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $sth=$dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
auth_tag_structure where tagfield=?");
+       $sth->execute($searchfield);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                                                       searchfield => 
$searchfield,
+                                                       authtypecode => 
$authtypecode,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       unless (C4::Context->config('demo') eq 1) {
+               $dbh->do("delete from auth_tag_structure where 
tagfield='$searchfield' and authtypecode='$authtypecode'");
+               $dbh->do("delete from auth_subfield_structure where 
tagfield='$searchfield' and authtypecode='$authtypecode'");
+       }
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## ITEMTYPE_CREATE ##################################
+# called automatically if an unexisting authtypecode is selected
+} elsif ($op eq 'authtype_create') {
+       $sth = $dbh->prepare("select 
count(*),auth_tag_structure.authtypecode,authtypetext from 
auth_tag_structure,auth_types where 
auth_types.authtypecode=auth_tag_structure.authtypecode group by 
auth_tag_structure.authtypecode");
+       $sth->execute;
+       my @existingauthtypeloop;
+       while (my ($tot,$thisauthtype,$authtypetext) = $sth->fetchrow) {
+               if ($tot>0) {
+                       my %line = ( value => $thisauthtype,
+                                               authtypetext => $authtypetext,
+                                       );
+                       push @existingauthtypeloop,\%line;
+               }
+       }
+       $template->param(existingauthtypeloop => address@hidden,
+                                       authtypecode => $authtypecode,
+                                       );
+################## DEFAULT ##################################
+} else { # DEFAULT
+       # here, $op can be unset or set to "authtype_create_confirm".
+#      warn "authtype : $authtypecode";
+       if  ($searchfield ne '') {
+                $template->param(searchfield => $searchfield);
+       }
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,$authtypecode);
+       my $toggle="white";
+       my @loop_data = ();
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               if ($toggle eq 'white'){
+                       $toggle="#ffffcc";
+               } else {
+                       $toggle="white";
+               }
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{tagfield} = $results->[$i]{'tagfield'};
+               $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
+               $row_data{repeatable} = $results->[$i]{'repeatable'};
+               $row_data{mandatory} = $results->[$i]{'mandatory'};
+               $row_data{authorised_value} = 
$results->[$i]{'authorised_value'};
+               $row_data{subfield_link} 
="auth_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'}."&authtypecode=".$authtypecode;
+               $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results->[$i]{'tagfield'}."&authtypecode=".$authtypecode;
+               $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'tagfield'}."&authtypecode=".$authtypecode;
+               $row_data{bgcolor} = $toggle;
+               push(@loop_data, \%row_data);
+       }
+       $template->param(loop => address@hidden,
+                                       authtypecode => $authtypecode,
+       );
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(isprevpage => $offset,
+                                               prevpage=> $prevpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                );
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(nextpage =>$nextpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+               );
+       }
+} #---- END $OP eq DEFAULT
+
+$template->param(loggeninuser => $loggedinuser);
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+#
+# the sub used for searches
+#
+sub StringSearch  {
+       my ($env,$searchstring,$authtypecode)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
auth_tag_structure where (tagfield >= ? and authtypecode=?) order by tagfield");
+       $sth->execute($data[0], $authtypecode);
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+#
+# the sub used to duplicate a framework from an existing one in MARC 
parameters tables.
+#
+sub duplicate_auth_framework {
+       my ($newauthtype,$oldauthtype) = @_;
+#      warn "TO $newauthtype FROM $oldauthtype";
+       my $sth = $dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
auth_tag_structure where authtypecode=?");
+       $sth->execute($oldauthtype);
+       my $sth_insert = $dbh->prepare("insert into auth_tag_structure  
(tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, 
authtypecode) values (?,?,?,?,?,?,?)");
+       while ( my 
($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value) = 
$sth->fetchrow) {
+               
$sth_insert->execute($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value,$newauthtype);
+       }
+
+       $sth = $dbh->prepare("select 
tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,value_builder,seealso,hidden,link
 from auth_subfield_structure where authtypecode=?");
+       $sth->execute($oldauthtype);
+       $sth_insert = $dbh->prepare("insert into auth_subfield_structure 
(authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,value_builder,seealso,hidden,link)
 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+       while ( my ( $tagfield, $tagsubfield, $liblibrarian, $libopac, 
$repeatable, $mandatory, $kohafield,$tab, $authorised_value, 
$thesaurus_category, $seealso,$hidden,$link) = $sth->fetchrow) {
+               $sth_insert->execute($newauthtype, $tagfield, $tagsubfield, 
$liblibrarian, $libopac, $repeatable, $mandatory,$kohafield, $tab, 
$authorised_value, $thesaurus_category, $seealso,$hidden,$link);
+       }
+}
+

Index: authorised_values.pl
===================================================================
RCS file: authorised_values.pl
diff -N authorised_values.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ authorised_values.pl        25 Mar 2007 23:14:17 -0000      1.18.2.2
@@ -0,0 +1,207 @@
+#!/usr/bin/perl
+
+# 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::Auth;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+use C4::Context;
+
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select id,category,authorised_value,lib from 
authorised_values where (category like ?) order by category,authorised_value");
+       $sth->execute("$data[0]%");
+       my @results;
+       my $cnt=0;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       $cnt ++;
+       }
+       $sth->finish;
+       return ($cnt,address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('searchfield');
+$searchfield=~ s/\,//g;
+my $id = $input->param('id');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/authorised_values.pl";
+my $dbh = C4::Context->dbh;
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/authorised_values.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1, management => 
1},
+                            debug => 1,
+                            });
+my $pagesize=20;
+my $op = $input->param('op');
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       my $data;
+       if ($id) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select id,category,authorised_value,lib 
from authorised_values where id=?");
+               $sth->execute($id);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       } else {
+               $data->{'category'} = $input->param('category');
+       }
+       if ($searchfield) {
+               $template->param(action => "Modify authorised value");
+               $template->param('heading-modify-authorized-value-p' => 1);
+       } elsif ( ! $data->{'category'} ) {
+               $template->param(action => "Add new category");
+               $template->param('heading-add-new-category-p' => 1);
+       } else {
+               $template->param(action => "Add authorised value");
+               $template->param('heading-add-authorized-value-p' => 1);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(category => $data->{'category'},
+                                                       authorised_value => 
$data->{'authorised_value'},
+                                                       lib => $data->{'lib'},
+                                                       id => $data->{'id'}
+                                                       );
+       if ($data->{'category'}) {
+               $template->param(category => "<input type=\"hidden\" 
name=\"category\" value='$data->{'category'}'>$data->{'category'}");
+       } else {
+               $template->param(category => "<input type=text 
name=\"category\" size=8 maxlength=8>");
+       }
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace authorised_values 
(id,category,authorised_value,lib) values (?,?,?,?)");
+       my $lib = $input->param('lib');
+       undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
+       
+       $sth->execute($input->param('id'), $input->param('category'), 
$input->param('authorised_value'), $lib);
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=authorised_values.pl?searchfield=".$input->param('category')."\"></html>";
+       exit;
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select category,authorised_value,lib from 
authorised_values where id=?");
+       $sth->execute($id);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       
+       $template->param(searchfield => $searchfield,
+                                                       Tvalue => 
$data->{'authorised_value'},
+                                                       id =>$id,
+                                                       );
+
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("delete from authorised_values where id=?");
+       $sth->execute($id);
+       $sth->finish;
+       
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=authorised_values.pl?searchfield=$searchfield\"></html>";
+       exit;
+
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       # build categories list
+       my $sth = $dbh->prepare("select distinct category from 
authorised_values");
+       $sth->execute;
+       my @category_list;
+       while ( my ($category) = $sth->fetchrow_array) {
+               push(@category_list,$category);
+       }
+       # push koha system categories
+       my $tab_list = CGI::scrolling_list(-name=>'searchfield',
+                       -values=> address@hidden,
+                       -default=>"",
+                       -size=>1,
+                       -multiple=>0,
+                       );
+       if (!$searchfield) {
+               $searchfield=$category_list[0];
+       }
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my $toggle="white";
+       my @loop_data = ();
+       # builds value list
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               if ($toggle eq 'white'){
+                       $toggle="#ffffcc";
+               } else {
+                       $toggle="white";
+               }
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{category} = $results->[$i]{'category'};
+               $row_data{authorised_value} = 
$results->[$i]{'authorised_value'};
+               $row_data{lib} = $results->[$i]{'lib'};
+               $row_data{edit} = 
"$script_name?op=add_form&id=".$results->[$i]{'id'};
+               $row_data{delete} = 
"$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'};
+               push(@loop_data, \%row_data);
+       }
+
+       $template->param(loop => address@hidden,
+                                                       tab_list => $tab_list,
+                                                       category => 
$searchfield);
+
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(isprevpage => $offset,
+                                               prevpage=> $prevpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                );
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(nextpage =>$nextpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+               );
+       }
+} #---- END $OP eq DEFAULT
+
+output_html_with_http_headers $input, $cookie, $template->output;

Index: authtypes.pl
===================================================================
RCS file: authtypes.pl
diff -N authtypes.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ authtypes.pl        25 Mar 2007 23:14:17 -0000      1.6.2.2
@@ -0,0 +1,177 @@
+#!/usr/bin/perl
+# NOTE: 4-character tabs
+
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# 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::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from auth_types where (authtypecode 
like ?) order by authtypecode");
+       $sth->execute("$data[0]%");
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('authtypecode');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/authtypes.pl";
+my $authtypecode=$input->param('authtypecode');
+my $pagesize=20;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/authtypes.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #start the page and read in includes
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($authtypecode) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select * from auth_types where 
authtypecode=?");
+               $sth->execute($authtypecode);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+#      warn "=> $data->{'authtypetext'} : ".$data->{'summary'};
+       $template->param(authtypecode => $authtypecode,
+                                                       authtypetext => 
$data->{'authtypetext'},
+                                                       auth_tag_to_report => 
$data->{'auth_tag_to_report'},
+                                                       summary => 
$data->{'summary'},
+                                                       );
+;
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace auth_types 
(authtypecode,authtypetext,auth_tag_to_report,summary) values (?,?,?,?)");
+       
$sth->execute($input->param('authtypecode'),$input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'));
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=authtypes.pl\"></html>";
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       #start the page and read in includes
+       my $dbh = C4::Context->dbh;
+
+       my $total = 0;
+       for my $table ('auth_tag_structure') {
+          my $sth=$dbh->prepare("select count(*) as total from $table where 
authtypecode=?");
+          $sth->execute($authtypecode);
+          $total += $sth->fetchrow_hashref->{total};
+          $sth->finish;
+       }
+
+       my $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
+       $sth->execute($authtypecode);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+
+       $template->param(authtypecode => $authtypecode,
+                                                       authtypetext => 
$data->{'authtypetext'},
+                                                       summary => 
$data->{'summary'},
+                                                       total => $total);
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       #start the page and read in includes
+       my $dbh = C4::Context->dbh;
+       my $authtypecode=uc($input->param('authtypecode'));
+       my $sth=$dbh->prepare("delete from auth_tag_structure where 
authtypecode=?");
+       $sth->execute($authtypecode);
+       $sth=$dbh->prepare("delete from auth_subfield_structure where 
authtypecode=?");
+       $sth->execute($authtypecode);
+       $sth=$dbh->prepare("delete from auth_types where authtypecode=?");
+       $sth->execute($authtypecode);
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=authtypes.pl\"></html>";
+       exit;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my $toggle="white";
+       my @loop_data;
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               my %row_data;
+               if ($toggle eq 'white'){
+                       $row_data{toggle}="#ffffcc";
+               } else {
+                       $row_data{toggle}="white";
+               }
+               $row_data{authtypecode} = $results->[$i]{'authtypecode'};
+               $row_data{authtypetext} = $results->[$i]{'authtypetext'};
+               $row_data{auth_tag_to_report} = 
$results->[$i]{'auth_tag_to_report'};
+               $row_data{summary} = $results->[$i]{'summary'};
+               push(@loop_data, \%row_data);
+       }
+       $template->param(loop => address@hidden);
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(previous => "$script_name?offset=".$prevpage);
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(next => "$script_name?offset=".$nextpage);
+       }
+} #---- END $OP eq DEFAULT
+output_html_with_http_headers $input, $cookie, $template->output;
+
+# Local Variables:
+# tab-width: 4
+# End:

Index: biblios_framework.pl
===================================================================
RCS file: biblios_framework.pl
diff -N biblios_framework.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ biblios_framework.pl        25 Mar 2007 23:14:17 -0000      1.1.2.2
@@ -0,0 +1,177 @@
+#!/usr/bin/perl
+# NOTE: 4-character tabs
+
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# 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::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from biblios_framework where 
(frameworkcode like ?) order by frameworktext");
+       $sth->execute("$data[0]%");
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('frameworkcode');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/biblios_framework.pl";
+my $frameworkcode=$input->param('frameworkcode');
+my $pagesize=20;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/biblios_framework.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #start the page and read in includes
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($frameworkcode) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select * from biblios_framework where 
frameworkcode=?");
+               $sth->execute($frameworkcode);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       $template->param(frameworkcode => $frameworkcode,
+                                                       frameworktext => 
$data->{'frameworktext'},
+                                                       );
+;
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace biblios_framework 
(frameworkcode,frameworktext) values (?,?)");
+       
$sth->execute($input->param('frameworkcode'),$input->param('frameworktext'));
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=biblios_framework.pl\"></html>";
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       #start the page and read in includes
+       my $dbh = C4::Context->dbh;
+
+       # Check both categoryitem and biblioitems, see Bug 199
+       my $total = 0;
+       for my $table ('biblios_tag_structure') {
+          my $sth=$dbh->prepare("select count(*) as total from $table where 
frameworkcode=?");
+          $sth->execute($frameworkcode);
+          $total += $sth->fetchrow_hashref->{total};
+          $sth->finish;
+       }
+
+       my $sth=$dbh->prepare("select * from biblios_framework where 
frameworkcode=?");
+       $sth->execute($frameworkcode);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+
+       $template->param(frameworkcode => $frameworkcode,
+                                                       frameworktext => 
$data->{'frameworktext'},
+                                                       total => $total);
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       #start the page and read in includes
+       my $dbh = C4::Context->dbh;
+       my $frameworkcode=uc($input->param('frameworkcode'));
+       my $sth=$dbh->prepare("delete from biblios_tag_structure where 
frameworkcode=?");
+       $sth->execute($frameworkcode);
+       $sth=$dbh->prepare("delete from biblios_subfield_structure where 
frameworkcode=?");
+       $sth->execute($frameworkcode);
+       $sth=$dbh->prepare("delete from biblios_framework where 
frameworkcode=?");
+       $sth->execute($frameworkcode);
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=biblios_framework.pl\"></html>";
+       exit;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my $toggle="white";
+       my @loop_data;
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               my %row_data;
+               if ($toggle eq 'white'){
+                       $row_data{toggle}="#ffffcc";
+               } else {
+                       $row_data{toggle}="white";
+               }
+               $row_data{frameworkcode} = $results->[$i]{'frameworkcode'};
+               $row_data{frameworktext} = $results->[$i]{'frameworktext'};
+               push(@loop_data, \%row_data);
+       }
+       $template->param(loop => address@hidden);
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(previous => "$script_name?offset=".$prevpage);
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(next => "$script_name?offset=".$nextpage);
+       }
+} #---- END $OP eq DEFAULT
+output_html_with_http_headers $input, $cookie, $template->output;
+
+# Local Variables:
+# tab-width: 4
+# End:

Index: biblios_subfields_structure.pl
===================================================================
RCS file: biblios_subfields_structure.pl
diff -N biblios_subfields_structure.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ biblios_subfields_structure.pl      25 Mar 2007 23:14:17 -0000      1.1.2.2
@@ -0,0 +1,467 @@
+#!/usr/bin/perl
+
+
+# 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 C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Auth;
+use CGI;
+use C4::Search;
+use C4::Context;
+
+sub StringSearch  {
+       my ($env,$searchstring,$frameworkcode)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from biblios_subfield_structure where 
(tagfield like ? and frameworkcode=?) order by tagfield");
+       $sth->execute("$searchstring%",$frameworkcode);
+       my @results;
+       my $cnt=0;
+       my $u=1;
+       while (my $data=$sth->fetchrow_hashref){
+               push(@results,$data);
+               $cnt ++;
+               $u++;
+       }
+       $sth->finish;
+       $dbh->disconnect;
+       return ($cnt,address@hidden);
+}
+
+my $input = new CGI;
+my $tagfield=$input->param('tagfield');
+my $tagsubfield=$input->param('tagsubfield');
+my $frameworkcode=$input->param('frameworkcode');
+my $pkfield="tagfield";
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/biblios_subfields_structure.pl";
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => 
"admin/biblios_subfields_structure.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+my $pagesize=30;
+my $op = $input->param('op');
+$tagfield=~ s/\,//g;
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               tagfield =>$tagfield,
+                                               frameworkcode => $frameworkcode,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               tagfield =>$tagfield,
+                                               frameworkcode => $frameworkcode,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       my $data;
+       my $dbh = C4::Context->dbh;
+       my $more_subfields = $input->param("more_subfields")+1;
+       
+       
+       # build authorised value list
+       
+my     $sth2 = $dbh->prepare("select distinct category from 
authorised_values");
+       $sth2->execute;
+       my @authorised_values;
+       push @authorised_values,"";
+       while ((my $category) = $sth2->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       push (@authorised_values,"branches");
+       push (@authorised_values,"itemtypes");
+       # build thesaurus categories list
+       $sth2->finish;
+       $sth2 = $dbh->prepare("select authtypecode from auth_types");
+       $sth2->execute;
+       my @authtypes;
+       push @authtypes,"";
+       while ((my $authtypecode) = $sth2->fetchrow_array) {
+               push @authtypes, $authtypecode;
+       }
+       # build value_builder list
+       my @value_builder=('');
+
+       # read value_builder directory.
+       # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
+       # on a standard install, /cgi-bin need to be added. 
+       # test one, then the other
+       my $cgidir = C4::Context->intranetdir ."/cgi-bin";
+       unless (opendir(DIR, "$cgidir/value_builder")) {
+               $cgidir = C4::Context->intranetdir;
+               opendir(DIR, "$cgidir/value_builder") || die "can't opendir 
$cgidir/value_builder: $!";
+       } 
+       while (my $line = readdir(DIR)) {
+               if ($line =~ /\.pl$/) {
+                       push (@value_builder,$line);
+               }
+       }
+       closedir DIR;
+
+       # build values list
+       my $sth=$dbh->prepare("select * from biblios_subfield_structure where 
tagfield=? and frameworkcode=?"); # and tagsubfield='$tagsubfield'");
+       $sth->execute($tagfield,$frameworkcode);
+       my @loop_data = ();
+       my $toggle=1;
+       my $i=0;
+       while ($data =$sth->fetchrow_hashref) {
+               my %row_data;  # get a fresh hash for the row data
+               if ($toggle eq 1){
+                       $toggle=0;
+               } else {
+                       $toggle=1;
+               }
+               $row_data{tab} = CGI::scrolling_list(-name=>'tab',
+                                       -id=>"tab$i",
+                                       
-values=>['-1','0','1','2','3','4','5','6','7','8','9'],
+                                       -labels => {'-1' 
=>'ignore','0'=>'0','1'=>'1','2' =>'2','3'=>'3','4'=>'4',
+                                                                       '5' 
=>'5','6'=>'6','7'=>'7',
+                                                                       '8' 
=>'8','9'=>'9',},
+                                       -default=>$data->{'tab'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
+                                       -id=>"ohidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>substr($data->{'hidden'},0,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
+                                       -id=>"ihidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>substr($data->{'hidden'},1,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
+                                       -id=>"ehidden$i",
+                                       -values=>['0','1','2'],
+                                       -labels => {'0'=>'Show','1'=>'Show 
Collapsed',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>substr($data->{'hidden'},2,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{tagsubfield} =$data->{'tagsubfield'}."<input 
type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" 
id=\"tagsubfield\">";
+               $row_data{liblibrarian} = 
CGI::escapeHTML($data->{'liblibrarian'});
+               $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
+               $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
+               
+               $row_data{authorised_value}  = 
CGI::scrolling_list(-name=>'authorised_value',
+                                       -id=>'authorised_value',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'authorised_value'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{value_builder}  = 
CGI::scrolling_list(-name=>'value_builder',
+                                       -id=>'value_builder',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'value_builder'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{authtypes}  = 
CGI::scrolling_list(-name=>'authtypecode',
+                                       -id=>'authtypecode',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'authtypecode'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{repeatable} = CGI::checkbox(-name=>"repeatable$i",
+       -checked => $data->{'repeatable'}?'checked':'',
+       -value => 1,
+       -label => '',
+       -id => "repeatable$i");
+               $row_data{mandatory} = CGI::checkbox(-name => "mandatory$i",
+       -checked => $data->{'mandatory'}?'checked':'',
+       -value => 1,
+       -label => '',
+       -id => "mandatory$i");
+               $row_data{hidden} = CGI::escapeHTML($data->{hidden});
+               $row_data{isurl} = CGI::checkbox( -name => "isurl$i",
+                       -id => "isurl$i",
+                       -checked => $data->{'isurl'}?'checked':'',
+                       -value => 1,
+                       -label => '');
+               $row_data{row} = $i;
+               $row_data{toggle} = $toggle;
+               $row_data{link} = CGI::escapeHTML($data->{'link'});
+               push(@loop_data, \%row_data);
+               $i++;
+       }
+       # add more_subfields empty lines for add if needed
+       for (my $i=1;$i<=$more_subfields;$i++) {
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{tab} = CGI::scrolling_list(-name=>'tab',
+                                       -id => "tab$i",
+                                       
-values=>['-1','0','1','2','3','4','5','6','7','8','9'],
+                                       -labels => {'-1' 
=>'ignore','0'=>'0','1'=>'1',
+                                                                       '2' 
=>'2','3'=>'3','4'=>'4',
+                                                                       '5' 
=>'5','6'=>'6','7'=>'7',
+                                                                       '8' 
=>'8','9'=>'9',
+                                                                       },
+                                       -default=>"",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
+                                       -id=>"ohidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+
+               $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
+                                       -id=>"ihidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
+                                       -id=>"ehidden$i",
+                                       -values=>['0','1','2'],
+                                       -labels => {'0'=>'Show','1'=>'Show 
Collapsed',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{tagsubfield} = "<input type=\"text\" 
name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" 
id=\"tagsubfield\" maxlength=\"1\">";
+               $row_data{liblibrarian} = "";
+               $row_data{libopac} = "";
+               $row_data{seealso} = "";
+               $row_data{hidden} = "000";
+               $row_data{repeatable} = CGI::checkbox( -name=> 'repeatable',
+                               -id => "repeatable$i",
+                               -checked => '',
+                               -value => 1,
+                               -label => '');
+               $row_data{mandatory} = CGI::checkbox( -name=> 'mandatory',
+                       -id => "mandatory$i",
+                       -checked => '',
+                       -value => 1,
+                       -label => '');
+               $row_data{isurl} = CGI::checkbox(-name => 'isurl',
+                       -id => "isurl$i",
+                       -checked => '',
+                       -value => 1,
+                       -label => '');
+               
+               $row_data{authorised_value}  = 
CGI::scrolling_list(-name=>'authorised_value',
+                                       -id => 'authorised_value',
+                                       -values=> address@hidden,
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{authtypes}  = 
CGI::scrolling_list(-name=>'authtypecode',
+                                       -id => 'authtypecode',
+                                       -values=> address@hidden,
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{link} = CGI::escapeHTML($data->{'link'});
+               $row_data{toggle} = $toggle;
+               $row_data{row} = $i;
+               push(@loop_data, \%row_data);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param('heading-edit-subfields-p' => 1);
+       $template->param(action => "Edit subfields",
+                                                       tagfield => "<input 
type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
+                                                       loop => address@hidden,
+                                                       more_subfields => 
$more_subfields,
+                                                       more_tag => $tagfield);
+
+                                                                               
                # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       $template->param(tagfield => "$input->param('tagfield')");
+       my $sth=$dbh->prepare("replace biblios_subfield_structure 
(tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode,
 link)
+                                                                       values 
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+       my @tagsubfield = $input->param('tagsubfield');
+       my @liblibrarian        = $input->param('liblibrarian');
+       my @libopac             = $input->param('libopac');
+
+       my @tab                         = $input->param('tab');
+       my @seealso             = $input->param('seealso');
+#      my @hidden              = $input->param('hidden');
+       my @hidden;
+       my @ohidden             = $input->param('ohidden');
+       my @ihidden             = $input->param('ihidden');
+       my @ehidden             = $input->param('ehidden');
+       my @authorised_values   = $input->param('authorised_value');
+       my @authtypecodes       = $input->param('authtypecode');
+       my @value_builder       =$input->param('value_builder');
+       my @link                =$input->param('link');
+       for (my $i=0; $i<= $#tagsubfield ; $i++) {
+               my $tagfield                    =$input->param('tagfield');
+               my $tagsubfield         =$tagsubfield[$i];
+               $tagsubfield="@" unless $tagsubfield ne '';
+               my $liblibrarian                =$liblibrarian[$i];
+               my $libopac                     =$libopac[$i];
+               my $repeatable          =$input->param("repeatable$i")?1:0;
+               my $mandatory           =$input->param("mandatory$i")?1:0;
+       
+               my $tab                         =$tab[$i];
+               my $seealso                             =$seealso[$i];
+               my $authorised_value            =$authorised_values[$i];
+               my $authtypecode                =$authtypecodes[$i];
+               my $value_builder=$value_builder[$i];
+               my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate 
from 3 hiddens;
+               my $isurl = $input->param("isurl$i")?1:0;
+               my $link = $link[$i];
+               if ($liblibrarian) {
+                       unless (C4::Context->config('demo') eq 1) {
+                               $sth->execute ($tagfield,
+                                                                       
$tagsubfield,
+                                                                       
$liblibrarian,
+                                                                       
$libopac,
+                                                                       
$repeatable,
+                                                                       
$mandatory,
+                                                                       
+                                                                       $tab,
+                                                                       
$seealso,
+                                                                       
$authorised_value,
+                                                                       
$authtypecode,
+                                                                       
$value_builder,
+                                                                       $hidden,
+                                                                       $isurl,
+                                                                       
$frameworkcode,
+
+        $link,
+                                             );
+                       }
+               }
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=biblios_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+       exit;
+
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select * from biblios_subfield_structure where 
tagfield=? and tagsubfield=? and frameworkcode=?");
+       #FIXME : called with 2 bind variables when 3 are needed
+       $sth->execute($tagfield,$tagsubfield);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                                                       tagsubfield => 
$data->{'tagsubfield'},
+                                                       delete_link => 
$script_name,
+                                                       tagfield      
=>$tagfield,
+                                                       tagsubfield => 
$tagsubfield,
+                                                       frameworkcode => 
$frameworkcode,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       my $dbh = C4::Context->dbh;
+       unless (C4::Context->config('demo') eq 1) {
+               my $sth=$dbh->prepare("delete from biblios_subfield_structure 
where tagfield=? and tagsubfield=? and frameworkcode=?");
+               $sth->execute($tagfield,$tagsubfield,$frameworkcode);
+               $sth->finish;
+       }
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=biblios_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+       exit;
+       $template->param(tagfield => $tagfield);
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       my $env;
+       my ($count,$results)=StringSearch($env,$tagfield,$frameworkcode);
+       my $toggle=1;
+       my @loop_data = ();
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               if ($toggle eq 1){
+                       $toggle=0;
+               } else {
+                       $toggle=1;
+               }
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{tagfield} = $results->[$i]{'tagfield'};
+               $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
+               $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
+               $row_data{repeatable} = $results->[$i]{'repeatable'};
+               $row_data{mandatory} = $results->[$i]{'mandatory'};
+               $row_data{tab} = $results->[$i]{'tab'};
+               $row_data{seealso} = $results->[$i]{'seealso'};
+               $row_data{authorised_value} = 
$results->[$i]{'authorised_value'};
+               $row_data{authtypecode} = $results->[$i]{'authtypecode'};
+               $row_data{value_builder}        = 
$results->[$i]{'value_builder'};
+               $row_data{hidden}       = $results->[$i]{'hidden'} 
if($results->[$i]{'hidden'} gt "000") ;
+               $row_data{isurl}        = $results->[$i]{'isurl'};
+               $row_data{link} = $results->[$i]{'link'};
+               $row_data{delete} = 
"$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&frameworkcode=$frameworkcode";
+               $row_data{toggle} = $toggle;
+               if ($row_data{tab} eq -1) {
+                       $row_data{subfield_ignored} = 1;
+               }
+
+               push(@loop_data, \%row_data);
+       }
+       $template->param(loop => address@hidden);
+       $template->param(edit_tagfield => $tagfield,
+               edit_frameworkcode => $frameworkcode);
+       
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(prev =>"<a 
href=\"$script_name?offset=$prevpage\">");
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(next => "<a 
href=\"$script_name?offset=$nextpage\">");
+       }
+} #---- END $OP eq DEFAULT
+$template->param(intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;

Index: bibliostagstructure.pl
===================================================================
RCS file: bibliostagstructure.pl
diff -N bibliostagstructure.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ bibliostagstructure.pl      25 Mar 2007 23:14:17 -0000      1.1.2.2
@@ -0,0 +1,397 @@
+#!/usr/bin/perl
+
+
+# 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::Auth;
+use C4::Koha;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+
+
+# retrieve parameters
+my $input = new CGI;
+my $frameworkcode = $input->param('frameworkcode'); # set to select framework
+$frameworkcode="" unless $frameworkcode;
+my $existingframeworkcode = $input->param('existingframeworkcode'); # set when 
we have to create a new framework (in frameworkcode) by copying an old one (in 
existingframeworkcode)
+$existingframeworkcode = "" unless $existingframeworkcode;
+my $frameworkinfo = getframeworkinfo($frameworkcode);
+my $searchfield=$input->param('searchfield');
+$searchfield=0 unless $searchfield;
+$searchfield=~ s/\,//g;
+
+my $offset=$input->param('offset');
+my $op = $input->param('op');
+my $dspchoice = $input->param('select_display');
+my $pagesize=20;
+
+my $script_name="/cgi-bin/koha/admin/bibliostagstructure.pl";
+
+my $dbh = C4::Context->dbh;
+
+# open template
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/bibliostagstructure.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+# get framework list
+my $frameworks = getframeworks();
+my @frameworkloop;
+foreach my $thisframeworkcode (keys %$frameworks) {
+       my $selected = 1 if $thisframeworkcode eq $frameworkcode;
+       my %row =(value => $thisframeworkcode,
+                               selected => $selected,
+                               frameworktext => 
$frameworks->{$thisframeworkcode}->{'frameworktext'},
+                       );
+       push @frameworkloop, \%row;
+}
+
+# check that framework is defined in biblios_tag_structure
+my $sth=$dbh->prepare("select count(*) from biblios_tag_structure where 
frameworkcode=?");
+$sth->execute($frameworkcode);
+my ($frameworkexist) = $sth->fetchrow;
+if ($frameworkexist) {
+} else {
+       # if frameworkcode does not exists, then OP must be changed to "create 
framework" if we are not on the way to create it
+       # (op = itemtyp_create_confirm)
+       if ($op eq "framework_create_confirm") {
+               duplicate_framework($frameworkcode, $existingframeworkcode);
+               $op=""; # unset $op to go back to framework list
+       } else {
+               $op = "framework_create";
+       }
+}
+$template->param(frameworkloop => address@hidden,
+                               frameworkcode => $frameworkcode,
+                               frameworktext => 
$frameworkinfo->{frameworktext});
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               $sth=$dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
biblios_tag_structure where tagfield=? and frameworkcode=?");
+               $sth->execute($searchfield,$frameworkcode);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       my $sth = $dbh->prepare("select distinct category from 
authorised_values");
+       $sth->execute;
+       my @authorised_values;
+       push @authorised_values,"";
+       while ((my $category) = $sth->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       my $authorised_value  = CGI::scrolling_list(-name=>'authorised_value',
+                       -values=> address@hidden,
+                       -size=>1,
+                       -id=>"authorised_value",
+                       -multiple=>0,
+                       -default => $data->{'authorised_value'},
+                       );
+
+       if ($searchfield) {
+               $template->param(action => "Modify tag",
+                                                               searchfield => 
"<input type=\"hidden\" name=\"tagfield\" value=\"$searchfield\" 
/>$searchfield");
+               $template->param('heading-modify-tag-p' => 1);
+       } else {
+               $template->param(action => "Add tag",
+                                                               searchfield => 
"<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
+               $template->param('heading-add-tag-p' => 1);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                       libopac => $data->{'libopac'},
+                       repeatable => CGI::checkbox(-name=>'repeatable',
+                                               -checked=> 
$data->{'repeatable'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'repeatable'),
+                       mandatory => CGI::checkbox(-name => 'mandatory',
+                                               -checked => 
$data->{'mandatory'}?'checked':'',
+                                               -value => 1,
+                                               -label => '',
+                                               -id => 'mandatory'),
+                       authorised_value => $authorised_value,
+                       frameworkcode => $frameworkcode,
+                       );
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $sth=$dbh->prepare("replace biblios_tag_structure 
(tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,frameworkcode)
 values (?,?,?,?,?,?,?)");
+       my $tagfield       =$input->param('tagfield');
+       my $liblibrarian  = $input->param('liblibrarian');
+       my $libopac       =$input->param('libopac');
+       my $repeatable =$input->param('repeatable');
+       my $mandatory =$input->param('mandatory');
+       my $authorised_value =$input->param('authorised_value');
+       unless (C4::Context->config('demo') eq 1) {
+               $sth->execute($tagfield,
+                                                       $liblibrarian,
+                                                       $libopac,
+                                                       $repeatable?1:0,
+                                                       $mandatory?1:0,
+                                                       $authorised_value,
+                                                       $frameworkcode
+                                                       );
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=bibliostagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $sth=$dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
biblios_tag_structure where tagfield=? and frameworkcode=?");
+       $sth->execute($searchfield,$frameworkcode);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                                                       searchfield => 
$searchfield,
+                                                       frameworkcode => 
$frameworkcode,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       unless (C4::Context->config('demo') eq 1) {
+               $dbh->do("delete from biblios_tag_structure where 
tagfield='$searchfield' and frameworkcode='$frameworkcode'");
+               $dbh->do("delete from biblios_subfield_structure where 
tagfield='$searchfield' and frameworkcode='$frameworkcode'");
+               
+       }
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## ITEMTYPE_CREATE ##################################
+# called automatically if an unexisting  frameworkis selected
+} elsif ($op eq 'framework_create') {
+       $sth = $dbh->prepare("select 
count(*),biblios_tag_structure.frameworkcode,frameworktext from 
biblios_tag_structure,biblios_framework where 
biblios_framework.frameworkcode=biblios_tag_structure.frameworkcode group by 
biblios_tag_structure.frameworkcode");
+       $sth->execute;
+       my @existingframeworkloop;
+       while (my ($tot,$thisframeworkcode,$frameworktext) = $sth->fetchrow) {
+               if ($tot>0) {
+                       my %line = ( value => $thisframeworkcode,
+                                               frameworktext => $frameworktext,
+                                       );
+                       push @existingframeworkloop,\%line;
+               }
+       }
+       $template->param(existingframeworkloop => address@hidden,
+                                       frameworkcode => $frameworkcode,
+#                                      FRtext => 
$frameworkinfo->{frameworktext},
+                                       );
+################## DEFAULT ##################################
+} else { # DEFAULT
+       # here, $op can be unset or set to "framework_create_confirm".
+       if  ($searchfield ne '') {
+                $template->param(searchfield => $searchfield);
+       }
+       my $cnt=0;
+       if ($dspchoice) {
+               #here, user only wants used tags/subfields displayed
+               my $env;
+               $searchfield=~ s/\'/\\\'/g;
+               my @data=split(' ',$searchfield);
+               my $sth=$dbh->prepare("Select biblios_tag_structure.tagfield as 
mts_tagfield,biblios_tag_structure.liblibrarian as 
mts_liblibrarian,biblios_tag_structure.libopac as 
mts_libopac,biblios_tag_structure.repeatable as 
mts_repeatable,biblios_tag_structure.mandatory as 
mts_mandatory,biblios_tag_structure.authorised_value as 
mts_authorized_value,biblios_subfield_structure.* from biblios_tag_structure 
LEFT JOIN biblios_subfield_structure ON 
(biblios_tag_structure.tagfield=biblios_subfield_structure.tagfield AND 
biblios_tag_structure.frameworkcode=biblios_subfield_structure.frameworkcode) 
where (biblios_tag_structure.tagfield >= ? and 
biblios_tag_structure.frameworkcode=?) AND biblios_subfield_structure.tab>=0 
order by 
biblios_tag_structure.tagfield,biblios_subfield_structure.tagsubfield");
+               #could be ordoned by tab
+               $sth->execute($data[0], $frameworkcode);
+               my @results = ();
+               while (my $data=$sth->fetchrow_hashref){
+                       push(@results,$data);
+                       $cnt++;
+               }
+               $sth->finish;
+               
+               my $toggle=0;
+               my @loop_data = ();
+               my $j=1;
+               my $i=$offset;
+               while ($i < ($offset+$pagesize<$cnt?$offset+$pagesize:$cnt)) {
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{tagfield} = $results[$i]->{'mts_tagfield'};
+                       $row_data{liblibrarian} = 
$results[$i]->{'mts_liblibrarian'};
+                       $row_data{repeatable} = 
$results[$i]->{'mts_repeatable'};
+                       $row_data{mandatory} = $results[$i]->{'mts_mandatory'};
+                       $row_data{authorised_value} = 
$results[$i]->{'mts_authorised_value'};
+                       $row_data{subfield_link} 
="biblios_subfields_structure.pl?op=add_form&tagfield=".$results[$i]->{'mts_tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results[$i]->{'mts_tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'mts_tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{toggle} = $toggle;
+                       $j=$i;
+                       my @internal_loop = ();
+                       while 
(($results[$i]->{'tagfield'}==$results[$j]->{'tagfield'}) and ($j< 
($offset+$pagesize<$cnt?$offset+$pagesize:$cnt))) {
+                               if ($toggle eq 0) {
+                                       $toggle=1;
+                               } else {
+                                       $toggle=0;
+                               }
+                               my %subfield_data;
+                               $subfield_data{tagsubfield} = 
$results[$j]->{'tagsubfield'};
+                               $subfield_data{liblibrarian} = 
$results[$j]->{'liblibrarian'};
+                               $subfield_data{repeatable} = 
$results[$j]->{'repeatable'};
+                               $subfield_data{mandatory} = 
$results[$j]->{'mandatory'};
+                               $subfield_data{tab} = $results[$j]->{'tab'};
+                               $subfield_data{seealso} = 
$results[$j]->{'seealso'};
+                               $subfield_data{authorised_value} = 
$results[$j]->{'authorised_value'};
+                               $subfield_data{authtypecode}= 
$results[$j]->{'authtypecode'};
+                               $subfield_data{value_builder}= 
$results[$j]->{'value_builder'};
+                               $subfield_data{toggle}  = $toggle;
+#                              warn "tagfield :  
".$results[$j]->{'tagfield'}." tagsubfield :".$results[$j]->{'tagsubfield'};
+                               push @internal_loop,\%subfield_data;
+                               $j++;
+                       }
+                       $row_data{'subfields'address@hidden;
+                       push(@loop_data, \%row_data);
+#                      undef @internal_loop;
+                       $i=$j;
+               }
+               $template->param(select_display => "True",
+                                               loop => address@hidden);
+               #  $sth->execute;
+               $sth->finish;
+       } else {
+               #here, normal old style : display every tags
+               my $env;
+               my 
($count,$results)=StringSearch($env,$searchfield,$frameworkcode);
+               $cnt = $count;
+               my $toggle=0;
+               my @loop_data = ();
+               for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{tagfield} = $results->[$i]{'tagfield'};
+                       $row_data{liblibrarian} = 
$results->[$i]{'liblibrarian'};
+                       $row_data{repeatable} = $results->[$i]{'repeatable'};
+                       $row_data{mandatory} = $results->[$i]{'mandatory'};
+                       $row_data{authorised_value} = 
$results->[$i]{'authorised_value'};
+                       $row_data{subfield_link} 
="biblios_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results->[$i]{'tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{toggle} = $toggle;
+                       push(@loop_data, \%row_data);
+               }
+               $template->param(loop => address@hidden);
+       }
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(isprevpage => $offset,
+                                               prevpage=> $prevpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               frameworkcode => $frameworkcode,
+               );
+       }
+       if ($offset+$pagesize<$cnt) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(nextpage =>$nextpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               frameworkcode => $frameworkcode,
+               );
+       }
+} #---- END $OP eq DEFAULT
+
+$template->param(loggeninuser => $loggedinuser,
+               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+#
+# the sub used for searches
+#
+sub StringSearch  {
+       my ($env,$searchstring,$frameworkcode)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
biblios_tag_structure where (tagfield >= ? and frameworkcode=?) order by 
tagfield");
+       $sth->execute($data[0], $frameworkcode);
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+#
+# the sub used to duplicate a framework from an existing one in MARC 
parameters tables.
+#
+sub duplicate_framework {
+       my ($newframeworkcode,$oldframeworkcode) = @_;
+       my $sth = $dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
biblios_tag_structure where frameworkcode=?");
+       $sth->execute($oldframeworkcode);
+       my $sth_insert = $dbh->prepare("insert into biblios_tag_structure 
(tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, 
frameworkcode) values (?,?,?,?,?,?,?)");
+       while ( my 
($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value) = 
$sth->fetchrow) {
+               
$sth_insert->execute($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value,$newframeworkcode);
+       }
+
+       $sth = $dbh->prepare("select 
frameworkcode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,authorised_value,authtypecode,value_builder,seealso,hidden,isurl
 from biblios_subfield_structure where frameworkcode=?");
+       $sth->execute($oldframeworkcode);
+       $sth_insert = $dbh->prepare("insert into biblios_subfield_structure 
(frameworkcode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,authorised_value,authtypecode,value_builder,seealso,hidden,isurl)
 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+       while ( my ($frameworkcode, $tagfield, $tagsubfield, $liblibrarian, 
$libopac, $repeatable, $mandatory,  $tab, $authorised_value, 
$thesaurus_category, $value_builder, $seealso,$hidden,$isurl) = $sth->fetchrow) 
{
+           $sth_insert->execute($newframeworkcode, $tagfield, $tagsubfield, 
$liblibrarian, $libopac, $repeatable, $mandatory, $tab, $authorised_value, 
$thesaurus_category, $value_builder, $seealso,$hidden,$isurl);
+       }
+       
+## now the same for holdings
+       $sth = $dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
holdings_tag_structure where frameworkcode=?");
+       $sth->execute($oldframeworkcode);
+       my $sth_insert = $dbh->prepare("insert into holdings_tag_structure 
(tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, 
frameworkcode) values (?,?,?,?,?,?,?)");
+       while ( my 
($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value) = 
$sth->fetchrow) {
+               
$sth_insert->execute($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value,$newframeworkcode);
+       }
+
+       $sth = $dbh->prepare("select 
frameworkcode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,authorised_value,authtypecode,value_builder,seealso,hidden,isurl
 from holdings_subfield_structure where frameworkcode=?");
+       $sth->execute($oldframeworkcode);
+       $sth_insert = $dbh->prepare("insert into holdings_subfield_structure 
(frameworkcode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,authorised_value,authtypecode,value_builder,seealso,hidden,isurl)
 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+       while ( my ($frameworkcode, $tagfield, $tagsubfield, $liblibrarian, 
$libopac, $repeatable, $mandatory,  $tab, $authorised_value, 
$thesaurus_category, $value_builder, $seealso,$hidden,$isurl) = $sth->fetchrow) 
{
+           $sth_insert->execute($newframeworkcode, $tagfield, $tagsubfield, 
$liblibrarian, $libopac, $repeatable, $mandatory, $tab, $authorised_value, 
$thesaurus_category, $value_builder, $seealso,$hidden,$isurl);
+       }
+}
+

Index: branches.pl
===================================================================
RCS file: branches.pl
diff -N branches.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ branches.pl 25 Mar 2007 23:14:17 -0000      1.37.2.2
@@ -0,0 +1,509 @@
+#!/usr/bin/perl
+
+
+
+# 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::Auth;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+# Fixed variables
+my $linecolor1='#ffffcc';
+my $linecolor2='white';
+
+my $script_name="/cgi-bin/koha/admin/branches.pl";
+my $pagesize=20;
+
+
+#######################################################################################
+# Main loop....
+my $input = new CGI;
+my $branchcode=$input->param('branchcode');
+my $branchname=$input->param('branchname');
+my $categorycode = $input->param('categorycode');
+my $op = $input->param('op');
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/branches.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1, management => 
1},
+                            debug => 1,
+                            });
+if ($op) {
+       $template->param(script_name => $script_name,
+                               $op         => 1); # we show only the TMPL_VAR 
names $op
+} else {
+       $template->param(script_name => $script_name,
+                               else        => 1); # we show only the TMPL_VAR 
names $op
+}
+$template->param(action => $script_name);
+if ($op eq 'add') {
+       # If the user has pressed the "add new branch" button.
+       heading("Branches: Add Branch");
+       $template->param('heading-branches-add-branch-p' => 1);
+       $template->param('use-heading-flags-p' => 1);
+       editbranchform();
+
+} elsif ($op eq 'edit') {
+       # if the user has pressed the "edit branch settings" button.
+       heading("Branches: Edit Branch");
+       $template->param('heading-branches-edit-branch-p' => 1);
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(add => 1);
+       editbranchform($branchcode);
+} elsif ($op eq 'add_validate') {
+       # confirm settings change...
+       my $params = $input->Vars;
+       unless ($params->{'branchcode'} && $params->{'branchname'}) {
+               default ("Cannot change branch record: You must specify a 
Branchname and a Branchcode");
+       } else {
+               setbranchinfo($params);
+               $template->param(else => 1);
+               default ("Branch record changed for branch: 
$params->{'branchname'}");
+       }
+} elsif ($op eq 'delete') {
+       # if the user has pressed the "delete branch" button.
+       my $message = checkdatabasefor($branchcode);
+       if ($message) {
+               $template->param(else => 1);
+               default($message);
+       } else {
+               $template->param(branchname => $branchname);
+               $template->param(delete_confirm => 1);
+               $template->param(branchcode => $branchcode);
+       }
+} elsif ($op eq 'delete_confirmed') {
+       # actually delete branch and return to the main screen....
+       deletebranch($branchcode);
+       $template->param(else => 1);
+       default("The branch \"$branchname\" ($branchcode) has been deleted.");
+} elsif ($op eq 'editcategory') {
+       # If the user has pressed the "add new category" or "modify" buttons.
+       heading("Branches: Edit Category");
+       $template->param('heading-branches-edit-category-p' => 1);
+       $template->param('use-heading-flags-p' => 1);
+       editcatform($categorycode);
+} elsif ($op eq 'addcategory_validate') {
+       # confirm settings change...
+       my $params = $input->Vars;
+       unless ($params->{'categorycode'} && $params->{'categoryname'}) {
+               default ("Cannot change branch record: You must specify a 
Branchname and a Branchcode");
+       } else {
+               setcategoryinfo($params);
+               $template->param(else => 1);
+               default ("Category record changed for category 
$params->{'categoryname'}");
+       }
+} elsif ($op eq 'delete_category') {
+       # if the user has pressed the "delete branch" button.
+       my $message = checkcategorycode($categorycode);
+       if ($message) {
+               $template->param(else => 1);
+               default($message);
+       } else {
+               $template->param(delete_category => 1);
+               $template->param(categorycode => $categorycode);
+       }
+} elsif ($op eq 'categorydelete_confirmed') {
+       # actually delete branch and return to the main screen....
+       deletecategory($categorycode);
+       $template->param(else => 1);
+       default("The category with code $categorycode has been deleted.");
+
+} else {
+       # if no operation has been set...
+       default();
+}
+
+
+
+######################################################################################################
+#
+# html output functions....
+
+sub default {
+       my ($message) = @_;
+       heading("Branches");
+       $template->param('heading-branches-p' => 1);
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(message => $message);
+       $template->param(action => $script_name);
+       branchinfotable();
+}
+
+# FIXME: this function should not exist; otherwise headings are untranslatable
+sub heading {
+       my ($head) = @_;
+       $template->param(head => $head);
+}
+
+sub editbranchform {
+       # prepares the edit form...
+       my ($branchcode) = @_;
+       my $data;
+       if ($branchcode) {
+               $data = getbranchinfo($branchcode);
+               $data = $data->[0];
+               $template->param(branchcode => $data->{'branchcode'});
+               $template->param(branchname => $data->{'branchname'});
+               $template->param(branchaddress1 => $data->{'branchaddress1'});
+               $template->param(branchaddress2 => $data->{'branchaddress2'});
+               $template->param(branchaddress3 => $data->{'branchaddress3'});
+               $template->param(branchphone => $data->{'branchphone'});
+               $template->param(branchfax => $data->{'branchfax'});
+               $template->param(branchemail => $data->{'branchemail'});
+    }
+
+    # make the checkboxs.....
+    #
+    # We export a "categoryloop" array to the template, each element of which
+    # contains separate 'categoryname', 'categorycode', 'codedescription', and
+    # 'checked' fields. The $checked field is either '' or 'checked'
+    # (see bug 130)
+    #
+    my $catinfo = getcategoryinfo();
+    my $catcheckbox;
+#    print DEBUG "catinfo=".cvs($catinfo)."\n";
+    my @categoryloop = ();
+    foreach my $cat (@$catinfo) {
+       my $checked = "";
+       my $tmp = quotemeta($cat->{'categorycode'});
+       if (grep {/^$tmp$/} @{$data->{'categories'}}) {
+               $checked = "checked=\"checked\"";
+       }
+       push @categoryloop, {
+               categoryname    => $cat->{'categoryname'},
+               categorycode    => $cat->{'categorycode'},
+               codedescription => $cat->{'codedescription'},
+               checked         => $checked,
+           };
+       }
+       $template->param(categoryloop => address@hidden);
+
+    # {{{ Leave this here until bug 130 is completely resolved in the templates
+       for my $obsolete ('categoryname', 'categorycode', 'codedescription') {
+               $template->param($obsolete => 'Your template is out of date 
(bug 130)');
+       }
+    # }}}
+}
+
+sub editcatform {
+       # prepares the edit form...
+       my ($categorycode) = @_;
+       warn "cat : $categorycode";
+       my $data;
+       if ($categorycode) {
+               $data = getcategoryinfo($categorycode);
+               $data = $data->[0];
+               $template->param(categorycode => $data->{'categorycode'});
+               $template->param(categoryname => $data->{'categoryname'});
+               $template->param(codedescription => $data->{'codedescription'});
+    }
+}
+
+sub deleteconfirm {
+# message to print if the
+    my ($branchcode) = @_;
+}
+
+
+sub branchinfotable {
+# makes the html for a table of branch info from reference to an array of 
hashs.
+
+       my ($branchcode) = @_;
+       my $branchinfo;
+       if ($branchcode) {
+               $branchinfo = getbranchinfo($branchcode);
+       } else {
+               $branchinfo = getbranchinfo();
+       }
+       my $color;
+       my @loop_data =();
+       foreach my $branch (@$branchinfo) {
+               ($color eq $linecolor1) ? ($color=$linecolor2) : 
($color=$linecolor1);
+               #
+               # We export the following fields to the template. These are not
+               # pre-composed as a single "address" field because the template
+               # might (and should) escape what is exported here. (See bug 180)
+               #
+               # - color
+               # - branch_name     (Note: not "branchname")
+               # - branch_code     (Note: not "branchcode")
+               # - address         (containing a static error message)
+               # - branchaddress1 \
+               # - branchaddress2  |
+               # - branchaddress3  | comprising the old "address" field
+               # - branchphone     |
+               # - branchfax       |
+               # - branchemail    /
+               # - address-empty-p (1 if no address information, 0 otherwise)
+               # - categories      (containing a static error message)
+               # - category_list   (loop containing "categoryname")
+               # - no-categories-p (1 if no categories set, 0 otherwise)
+               # - value
+               # - action
+               #
+               my %row = ();
+
+               # Handle address fields separately
+               my $address_empty_p = 1;
+               for my $field ('branchaddress1', 'branchaddress2', 
'branchaddress3',
+                       'branchphone', 'branchfax', 'branchemail') {
+                       $row{$field} = $branch->{$field};
+                       if ( $branch->{$field} ) {
+                               $address_empty_p = 0;
+                       }
+               }
+               $row{'address-empty-p'} = $address_empty_p;
+               # {{{ Leave this here until bug 180 is completely resolved in 
templates
+               $row{'address'} = 'Your template is out of date (see bug 180)';
+               # }}}
+
+               # Handle categories
+               my $no_categories_p = 1;
+               my @categories = '';
+               foreach my $cat (@{$branch->{'categories'}}) {
+                       my ($catinfo) = @{getcategoryinfo($cat)};
+                       push @categories, {'categoryname' => 
$catinfo->{'categoryname'}};
+                       $no_categories_p = 0;
+               }
+               # {{{ Leave this here until bug 180 is completely resolved in 
templates
+               $row{'categories'} = 'Your template is out of date (see bug 
180)';
+               # }}}
+               $row{'category_list'} = address@hidden;
+               $row{'no-categories-p'} = $no_categories_p;
+
+               # Handle all other fields
+               $row{'branch_name'} = $branch->{'branchname'};
+               $row{'branch_code'} = $branch->{'branchcode'};
+               $row{'color'} = $color;
+               $row{'value'} = $branch->{'branchcode'};
+               $row{'action'} = '/cgi-bin/koha/admin/branches.pl';
+
+               push @loop_data, { %row };
+       }
+       my @branchcategories =();
+       my $catinfo = getcategoryinfo();
+       foreach my $cat (@$catinfo) {
+               push @branchcategories, {
+                       categoryname    => $cat->{'categoryname'},
+                       categorycode    => $cat->{'categorycode'},
+                       codedescription => $cat->{'codedescription'},
+               };
+       }
+
+       $template->param(branches => address@hidden,
+                                                       branchcategories => 
address@hidden);
+
+}
+
+# FIXME logic seems wrong
+sub branchcategoriestable {
+#Needs to be implemented...
+
+    my $categoryinfo = getcategoryinfo();
+    my $color;
+    foreach my $cat (@$categoryinfo) {
+       ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
+       $template->param(color => $color);
+       $template->param(categoryname => $cat->{'categoryname'});
+       $template->param(categorycode => $cat->{'categorycode'});
+       $template->param(codedescription => $cat->{'codedescription'});
+    }
+}
+
+######################################################################################################
+#
+# Database functions....
+
+sub getbranchinfo {
+# returns a reference to an array of hashes containing branches,
+
+    my ($branchcode) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth;
+    if ($branchcode) {
+               $sth = $dbh->prepare("Select * from branches where branchcode = 
? order by branchcode");
+               $sth->execute($branchcode);
+    } else {
+               $sth = $dbh->prepare("Select * from branches order by 
branchcode");
+               $sth->execute();
+    }
+    my @results;
+    while (my $data = $sth->fetchrow_hashref) {
+       my $nsth = $dbh->prepare("select categorycode from branchrelations 
where branchcode = ?");
+       $nsth->execute($data->{'branchcode'});;
+       my @cats = ();
+       while (my ($cat) = $nsth->fetchrow_array) {
+           push(@cats, $cat);
+       }
+       $nsth->finish;
+       $data->{'categories'} = address@hidden;
+       push(@results, $data);
+    }
+    $sth->finish;
+    return address@hidden;
+}
+
+# FIXME This doesn't belong here; it should be moved into a module
+sub getcategoryinfo {
+# returns a reference to an array of hashes containing branches,
+       my ($catcode) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth;
+       #    print DEBUG "getcategoryinfo: entry: catcode=".cvs($catcode)."\n";
+       if ($catcode) {
+               $sth = $dbh->prepare("select * from branchcategories where 
categorycode = ?");
+               $sth->execute($catcode);
+       } else {
+               $sth = $dbh->prepare("Select * from branchcategories");
+               $sth->execute();
+       }
+       my @results;
+       while (my $data = $sth->fetchrow_hashref) {
+               push(@results, $data);
+       }
+       $sth->finish;
+       #    print DEBUG "getcategoryinfo: exit: returning 
".cvs(address@hidden)."\n";
+       return address@hidden;
+}
+
+# FIXME This doesn't belong here; it should be moved into a module
+sub setbranchinfo {
+# sets the data from the editbranch form, and writes to the database...
+       my ($data) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace branches 
(branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail)
 values (?,?,?,?,?,?,?,?)");
+       $sth->execute(uc($data->{'branchcode'}), $data->{'branchname'},
+               $data->{'branchaddress1'}, $data->{'branchaddress2'},
+               $data->{'branchaddress3'}, $data->{'branchphone'},
+               $data->{'branchfax'}, $data->{'branchemail'});
+
+       $sth->finish;
+       # sort out the categories....
+       my @checkedcats;
+       my $cats = getcategoryinfo();
+       foreach my $cat (@$cats) {
+               my $code = $cat->{'categorycode'};
+               if ($data->{$code}) {
+                       push(@checkedcats, $code);
+               }
+       }
+       my $branchcode =uc($data->{'branchcode'});
+       my $branch = getbranchinfo($branchcode);
+       $branch = $branch->[0];
+       my $branchcats = $branch->{'categories'};
+       my @addcats;
+       my @removecats;
+       foreach my $bcat (@$branchcats) {
+               unless (grep {/^$bcat$/} @checkedcats) {
+                       push(@removecats, $bcat);
+               }
+       }
+       foreach my $ccat (@checkedcats){
+               unless (grep {/^$ccat$/} @$branchcats) {
+                       push(@addcats, $ccat);
+               }
+       }
+       foreach my $cat (@addcats) {
+               my $sth = $dbh->prepare("insert into branchrelations 
(branchcode, categorycode) values(?, ?)");
+               $sth->execute($branchcode, $cat);
+               $sth->finish;
+       }
+       foreach my $cat (@removecats) {
+               my $sth = $dbh->prepare("delete from branchrelations where 
branchcode=? and categorycode=?");
+               $sth->execute($branchcode, $cat);
+               $sth->finish;
+       }
+}
+
+sub deletebranch {
+# delete branch...
+    my ($branchcode) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth=$dbh->prepare("delete from branches where branchcode = ?");
+    $sth->execute($branchcode);
+    $sth->finish;
+}
+
+sub setcategoryinfo {
+# sets the data from the editbranch form, and writes to the database...
+       my ($data) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace branchcategories 
(categorycode,categoryname,codedescription) values (?,?,?)");
+       $sth->execute(uc($data->{'categorycode'}), 
$data->{'categoryname'},$data->{'codedescription'});
+
+       $sth->finish;
+}
+sub deletecategory {
+# delete branch...
+    my ($categorycode) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth=$dbh->prepare("delete from branchcategories where categorycode = 
?");
+    $sth->execute($categorycode);
+    $sth->finish;
+}
+
+sub checkdatabasefor {
+# check to see if the branchcode is being used in the database somewhere....
+    my ($branchcode) = @_;
+my @kohafield;
+my @value;
+my @relation;
+my @and_or;
+ push @kohafield, "holdingbranch","homebranch";
+push @value, $branchcode,$branchcode;
+push @and_or, "address@hidden";
+push @relation ,"address@hidden 5=100","address@hidden 5=100"; ##do not 
truncate
+     my ($total,@results) 
=ZEBRAsearch_kohafields(address@hidden,address@hidden, address@hidden,"", 
address@hidden,"","","",1);
+
+    my $message;
+    if ($total) {
+       # We do not return verbal messages but a flag. fix templates to accept 
$error=1 as a message
+       $message = "Branch cannot be deleted because there are $total items 
using that branch.";
+       
+    }
+    return $message;
+}
+
+sub checkcategorycode {
+# check to see if the branchcode is being used in the database somewhere....
+    my ($categorycode) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth=$dbh->prepare("select count(*) from branchrelations where 
categorycode=?");
+    $sth->execute($categorycode);
+    my ($total) = $sth->fetchrow_array;
+    $sth->finish;
+    my $message;
+    if ($total) {
+       # FIXME: need to be replaced by an exported boolean parameter
+       $message = "Category cannot be deleted because there are $total 
branches using that category.";
+    }
+    return $message;
+}
+
+output_html_with_http_headers $input, $cookie, $template->output;
+
+# Local Variables:
+# tab-width: 8
+# End:

Index: categorie.pl
===================================================================
RCS file: categorie.pl
diff -N categorie.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ categorie.pl        25 Mar 2007 23:14:17 -0000      1.24.2.2
@@ -0,0 +1,212 @@
+#!/usr/bin/perl
+
+#script to administer the categories table
+#written 20/02/2002 by address@hidden
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+
+# 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::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from categories where (description like 
?)");
+       $sth->execute("$data[0]%");
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('description');
+my $script_name="/cgi-bin/koha/admin/categorie.pl";
+my $categorycode=$input->param('categorycode');
+my $op = $input->param('op');
+
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/categorie.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+
+$template->param(script_name => $script_name,
+                categorycode => $categorycode,
+                searchfield => $searchfield);
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($categorycode) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,
 canmakepublicshelves, addRequestToShelves, allowrenewsfromopac from categories 
where categorycode=?");
+               $sth->execute($categorycode);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+
+       $template->param(description             => $data->{'description'},
+                               enrolmentperiod         => 
$data->{'enrolmentperiod'},
+                               upperagelimit           => 
$data->{'upperagelimit'},
+                               dateofbirthrequired     => 
$data->{'dateofbirthrequired'},
+                               enrolmentfee            => 
$data->{'enrolmentfee'},
+                               overduenoticerequired   => 
$data->{'overduenoticerequired'},
+                               issuelimit              => 
$data->{'issuelimit'},
+                               reservefee              => 
$data->{'reservefee'},
+                               canmakepublicshelves    => 
$data->{'canmakepublicshelves'},
+                               addRequestToShelves             => 
$data->{'addRequestToShelves'},
+                               allowrenewsfromopac             => 
$data->{'allowrenewsfromopac'}
+       );
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $template->param(add_validate => 1);
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace categories 
(categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,overduenoticerequired,
 issuelimit, canmakepublicshelves, addRequestToShelves , allowrenewsfromopac) 
values (?,?,?,?,?,?,?,?,?,?,?,?)");
+       $sth->execute(map { $input->param($_) } 
('categorycode','description','enrolmentperiod','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired',
 'issuelimit', 'canmakepublicshelves', 'addRequestToShelves', 
'allowrenewsfromopac'));
+       $sth->finish;
+       
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $template->param(delete_confirm => 1);
+
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select count(*) as total from borrowers where 
categorycode=?");
+       $sth->execute($categorycode);
+       my $total = $sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(total => $total->{'total'});
+       
+       my $sth2=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,
 canmakepublicshelves, addRequestToShelves,allowrenewsfromopac  from categories 
where categorycode=?");
+       $sth2->execute($categorycode);
+       my $data=$sth2->fetchrow_hashref;
+       $sth2->finish;
+       if ($total->{'total'} >0) {
+               $template->param(totalgtzero => 1);
+       }
+
+        $template->param(description             => $data->{'description'},
+                                enrolmentperiod         => 
$data->{'enrolmentperiod'},
+                                upperagelimit           => 
$data->{'upperagelimit'},
+                                dateofbirthrequired     => 
$data->{'dateofbirthrequired'},
+                                enrolmentfee            => 
$data->{'enrolmentfee'},
+                                overduenoticerequired   => 
$data->{'overduenoticerequired'},
+                                issuelimit              => 
$data->{'issuelimit'},
+                                reservefee              => 
$data->{'reservefee'},
+                                                               
canmakepublicshelves    => $data->{'canmakepublicshelves'},
+                                                               
addRequestToShelves             => $data->{'addRequestToShelves'},
+                                                               
allowrenewsfromopac     => $data->{'allowrenewsfromopac'},
+               
+               );
+
+
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       $template->param(delete_confirmed => 1);
+       my $dbh = C4::Context->dbh;
+       my $categorycode=uc($input->param('categorycode'));
+       my $sth=$dbh->prepare("delete from categories where categorycode=?");
+       $sth->execute($categorycode);
+       $sth->finish;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+} else { # DEFAULT
+       $template->param(else => 1);
+       my $env;
+       my @loop;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my $toggle = 0;
+       for (my $i=0; $i < $count; $i++){
+               my %row = (categorycode => $results->[$i]{'categorycode'},
+                               description => $results->[$i]{'description'},
+                               enrolmentperiod => 
$results->[$i]{'enrolmentperiod'},
+                               upperagelimit => 
$results->[$i]{'upperagelimit'},
+                               dateofbirthrequired => 
$results->[$i]{'dateofbirthrequired'},
+                               enrolmentfee => $results->[$i]{'enrolmentfee'},
+                               overduenoticerequired => 
$results->[$i]{'overduenoticerequired'},
+                               issuelimit => $results->[$i]{'issuelimit'},
+                               reservefee => $results->[$i]{'reservefee'},
+                               canmakepublicshelves => 
$results->[$i]{'canmakepublicshelves'},
+                               addRequestToShelves             => 
$results->[$i]{'addRequestToShelves'},
+                               allowrenewsfromopac => 
$results->[$i]{'allowrenewsfromopac'},
+                               toggle => $toggle );    
+               push @loop, \%row;
+               $toggle = not $toggle;
+       }
+       $template->param(loop => address@hidden);
+       # check that I (institution) and C (child) exists. otherwise => warning 
to the user
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select categorycode from categories where 
categorycode='C'");
+       $sth->execute;
+       my ($categoryChild) = $sth->fetchrow;
+       $template->param(categoryChild => $categoryChild);
+       $sth=$dbh->prepare("select categorycode from categories where 
categorycode='I'");
+       $sth->execute;
+       my ($categoryInstitution) = $sth->fetchrow;
+       $template->param(categoryInstitution => $categoryInstitution);
+       $sth->finish;
+
+
+} #---- END $OP eq DEFAULT
+
+
+
+output_html_with_http_headers $input, $cookie, $template->output;
+

Index: categoryitem.pl
===================================================================
RCS file: categoryitem.pl
diff -N categoryitem.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ categoryitem.pl     25 Mar 2007 23:14:17 -0000      1.12.2.2
@@ -0,0 +1,200 @@
+#!/usr/bin/perl
+
+#script to administer the categories table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+
+# 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::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from categories where (description like 
?)");
+       $sth->execute("$data[0]%");
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('description');
+my $script_name="/cgi-bin/koha/admin/categorie.pl";
+my $categorycode=$input->param('categorycode');
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+
+my ($template, $loggedinuser, $cookie) 
+    = get_template_and_user({template_name => "admin/categoryitem.tmpl",
+                             query => $input,
+                             type => "intranet",
+                             authnotrequired => 0,
+                             debug => 1,
+                             });
+
+
+$template->param(script_name => $script_name,
+                 categorycode => $categorycode,
+                searchfield => $searchfield);
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($categorycode) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,reservefee,overduenoticerequired
 from categories where categorycode=?");
+               $sth->execute($categorycode);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+
+        $template->param(description             => $data->{'description'},
+                                enrolmentperiod         => 
$data->{'enrolmentperiod'},
+                                upperagelimit           => 
$data->{'upperagelimit'},
+                                dateofbirthrequired     => 
$data->{'dateofbirthrequired'},
+                                finetype                => $data->{'finetype'},
+                                bulk                    => $data->{'bulk'},
+                                enrolmentfee            => 
$data->{'enrolmentfee'},
+                                overduenoticerequired   => 
$data->{'overduenoticerequired'},
+                                reservefee              => 
$data->{'reservefee'});
+
+
+;
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $template->param(add_validate => 1);
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace categories 
(categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,reservefee,overduenoticerequired)
 values (?,?,?,?,?,?,?,?,?,?)");
+       $sth->execute(map {$input->param($_)} 
('categorycode','description','enrolmentperiod','upperagelimit','dateofbirthrequired','finetype','bulk','enrolmentfee','reservefee','overduenoticerequired'));
+       $sth->finish;
+       print "data recorded";
+       print "<form action='$script_name' method=post>";
+       print "<input type=submit value=OK>";
+       print "</form>";
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $template->param(delete_confirm => 1);
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select count(*) as total from categoryitem where 
categorycode=?");
+       $sth->execute($categorycode);
+       my $total = $sth->fetchrow_hashref;
+       print "TOTAL : $categorycode : $total->{'total'}<br>";
+       $sth->finish;
+       my $sth2=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,reservefee,overduenoticerequired
 from categories where categorycode=?");
+       $sth2->execute($categorycode);
+       my $data=$sth2->fetchrow_hashref;
+       $sth2->finish;
+
+        $template->param(description             => $data->{'description'},
+                                enrolmentperiod         => 
$data->{'enrolmentperiod'},
+                                upperagelimit           => 
$data->{'upperagelimit'},
+                                dateofbirthrequired     => 
$data->{'dateofbirthrequired'},
+                                finetype                => $data->{'finetype'},
+                                bulk                    => $data->{'bulk'},
+                                enrolmentfee            => 
$data->{'enrolmentfee'},
+                                overduenoticerequired   => 
$data->{'overduenoticerequired'},
+                                reservefee              => 
$data->{'reservefee'});
+
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       $template->param(delete_confirmed => 1);
+       my $dbh = C4::Context->dbh;
+       my $categorycode=uc($input->param('categorycode'));
+       my $sth=$dbh->prepare("delete from categories where categorycode=?");
+       $sth->execute($categorycode);
+       $sth->finish;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+} else { # DEFAULT
+        $template->param(else => 1);
+        my $env;
+        my @loop;
+        my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my $toggle = 'white';
+        for (my $i=0; $i < $count; $i++){
+                my %row = (categorycode => $results->[$i]{'categorycode'},
+                                description => $results->[$i]{'description'},
+                                enrolmentperiod => 
$results->[$i]{'enrolmentperiod'},
+                                upperagelimit => 
$results->[$i]{'upperagelimit'},
+                                dateofbirthrequired => 
$results->[$i]{'dateofbirthrequired'},
+                                finetype => $results->[$i]{'finetype'},
+                                bulk => $results->[$i]{'bulk'},
+                                enrolmentfee => $results->[$i]{'enrolmentfee'},
+                                overduenoticerequired => 
$results->[$i]{'overduenoticerequired'},
+                                reservefee => $results->[$i]{'reservefee'},
+                               toggle => $toggle );
+                push @loop, \%row;
+                if ( $toggle eq 'white' )
+                {
+                        $toggle = '#ffffcc';
+                }
+                else
+                {
+                        $toggle = 'white';
+                }
+
+        }
+        $template->param(loop => address@hidden);
+
+
+} #---- END $OP eq DEFAULT
+
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+

Index: checkmarc.pl
===================================================================
RCS file: checkmarc.pl
diff -N checkmarc.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ checkmarc.pl        25 Mar 2007 23:14:17 -0000      1.10.2.2
@@ -0,0 +1,129 @@
+#!/usr/bin/perl
+
+
+# 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 C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Auth;
+use CGI;
+use C4::Search;
+use C4::Context;
+use C4::Biblio;
+
+my $input = new CGI;
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/checkmarc.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+my $dbh = C4::Context->dbh;
+my $total;
+# checks itemnumber field
+my $sth = $dbh->prepare("select tagfield from koha_attr where 
kohafield=\"itemnumber\"");
+$sth->execute;
+my ($res) = $sth->fetchrow;
+unless ($res) {
+       $template->param(itemnumber => 1);
+       $total++;
+}
+#check biblionumber
+my $sth = $dbh->prepare("select tagfield from koha_attr where 
kohafield=\"biblionumber\"");
+$sth->execute;
+my ($res) = $sth->fetchrow;
+if ($res ){
+       ($res) = $sth->fetchrow;
+       unless ($res){
+       $template->param(biblionumber => 1);
+       $total++;
+       }
+}
+#check barcode
+my $sth = $dbh->prepare("select tagfield from koha_attr where 
kohafield=\"barcode\"");
+$sth->execute;
+my ($res) = $sth->fetchrow;
+unless ($res){
+       $template->param(barcode=> 1);
+       $total++;
+}
+
+## Check for itemtype
+my $sth = $dbh->prepare("select tagfield,tagsubfield from koha_attr where 
kohafield=\"itemtype\"");
+$sth->execute;
+my ($res,$res2) = $sth->fetchrow;
+if ($res) {
+$sth = $dbh->prepare("select authorised_value from biblios_subfield_structure 
where tagfield=? and tagsubfield=?");
+$sth->execute($res,$res2);
+ my ($item)=$sth->fetchrow;
+    unless ($item eq "itemtypes"){
+       $template->param(itemtype => 1);
+       $total++;
+    }
+}
+
+## Check for homebranch
+my $sth = $dbh->prepare("select tagfield from koha_attr where 
kohafield=\"homebranch\"");
+$sth->execute;
+my ($res) = $sth->fetchrow;
+unless  ($res) {
+       $template->param(branch => 1);
+       $total++;
+    
+}
+
+## Check for holdingbranch
+my $sth = $dbh->prepare("select tagfield,tagsubfield from koha_attr where 
kohafield=\"holdingbranch\"");
+$sth->execute;
+my ($res,$res2) = $sth->fetchrow;
+if ($res) {
+$sth = $dbh->prepare("select authorised_value from holdings_subfield_structure 
where tagfield=? and tagsubfield=?");
+$sth->execute($res,$res2);
+ my ($item)=$sth->fetchrow;
+    unless ($item eq "branches"){
+       $template->param(holdingbranch => 1);
+       $total++;
+    }
+}
+
+
+
+# checks that itemtypes & branches tables are not empty
+$sth = $dbh->prepare("select count(*) from itemtypes");
+$sth->execute;
+($res) = $sth->fetchrow;
+unless ($res) {
+       $template->param(itemtypes_empty =>1);
+       $total++;
+}
+
+$sth = $dbh->prepare("select count(*) from branches");
+$sth->execute;
+($res) = $sth->fetchrow;
+unless ($res) {
+       $template->param(branches_empty =>1);
+       $total++;
+}
+
+$template->param(total => $total);
+output_html_with_http_headers $input, $cookie, $template->output;

Index: currency.pl
===================================================================
RCS file: currency.pl
diff -N currency.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ currency.pl 25 Mar 2007 23:14:17 -0000      1.14.2.2
@@ -0,0 +1,198 @@
+#!/usr/bin/perl
+
+#script to administer the aqbudget table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+
+# 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::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $query="Select currency,rate from currency where (currency like 
\"$data[0]%\") order by currency";
+       my $sth=$dbh->prepare($query);
+       $sth->execute;
+       my @results;
+       my $cnt=0;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       $cnt ++;
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return ($cnt,address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('searchfield');
+#my $branchcode=$input->param('branchcode');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/currency.pl";
+
+my $pagesize=20;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+
+my ($template, $loggedinuser, $cookie) 
+    = get_template_and_user({template_name => "admin/currency.tmpl",
+                             query => $input,
+                             type => "intranet",
+                            flagsrequired => {parameters => 1, management => 
1},
+                            authnotrequired => 0,
+                             debug => 1,
+                             });
+
+$template->param(searchfield => $searchfield,
+                script_name => $script_name);
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select currency,rate from currency where 
currency=?");
+               $sth->execute($searchfield);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+
+       $template->param(currency => $data->{'currency'},
+                        rate => $data->{'rate'});
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $template->param(add_validate => 1);
+       my $dbh = C4::Context->dbh;
+
+       my $check = $dbh->prepare("select * from currency where currency = ?");
+       $check->execute($input->param('currency'));
+       if ( $check->fetchrow )
+       {
+               my $sth = $dbh->prepare("UPDATE currency SET rate = ? WHERE 
currency = ?");
+               $sth->execute($input->param('rate'),$input->param('currency'));
+               $sth->finish;
+       }
+       else
+       {
+               my $sth = $dbh->prepare("INSERT INTO currency (currency, rate) 
VALUES (?,?)");
+               $sth->execute($input->param('currency'),$input->param('rate'));
+               $sth->finish;
+       }        
+
+       $check->finish;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $template->param(delete_confirm => 1);
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select count(*) as total from aqbooksellers 
where currency=?");
+       $sth->execute($searchfield);
+       my $total = $sth->fetchrow_hashref;
+       $sth->finish;
+       my $sth2=$dbh->prepare("select currency,rate from currency where 
currency=?");
+       $sth2->execute($searchfield);
+       my $data=$sth2->fetchrow_hashref;
+       $sth2->finish;
+
+       if ($total->{'total'} >0) {
+               $template->param(totalgtzero => 1);
+       }
+
+       $template->param(rate => $data->{'rate'},
+                        total => $total);
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       $template->param(delete_confirmed => 1);
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("delete from currency where currency=?");
+       $sth->execute($searchfield);
+       $sth->finish;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       $template->param(else => 1);
+
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my @loop;
+       my $toggle = 'white';
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               my %row = ( currency => $results->[$i]{'currency'},
+                           rate => $results->[$i]{'rate'},
+                           toggle => $toggle);
+               push @loop, \%row;
+
+                if ( $toggle eq 'white' )
+                {
+                        $toggle = '#ffffcc';
+                }
+                else
+                {
+                        $toggle = 'white';
+                }
+       }
+       $template->param(loop => address@hidden);
+
+       if ($offset>0) {
+               $template->param(offsetgtzero => 1,
+                                prevpage => $offset-$pagesize);
+       }
+
+       if ($offset+$pagesize<$count) {
+               $template->param(ltcount => 1,
+                                nextpage => $offset+$pagesize);
+       }
+} #---- END $OP eq DEFAULT
+
+output_html_with_http_headers $input, $cookie, $template->output;
+

Index: facets_labels.pl
===================================================================
RCS file: facets_labels.pl
diff -N facets_labels.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ facets_labels.pl    25 Mar 2007 23:14:17 -0000      1.1.2.1
@@ -0,0 +1,297 @@
+#!/usr/bin/perl
+
+
+# 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::Auth;
+use C4::Koha;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+
+
+# retrieve parameters
+my $input = new CGI;
+
+my $searchfield=$input->param('searchfield');
+$searchfield="" unless $searchfield;
+my $id=$input->param('id');
+my $offset=$input->param('offset');
+$offset=0 unless $offset;
+my $op = $input->param('op');
+my $dspchoice = $input->param('select_display');
+my $pagesize=20;
+my @results = ();
+my $script_name="/cgi-bin/koha/admin/facets_labels.pl";
+
+my $dbh = C4::Context->dbh;
+my $sth;
+# open template
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/facets_labels.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($id) {
+               $sth=$dbh->prepare("select * from facets where id=? ");
+               $sth->execute($id);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       my $sth = $dbh->prepare("select kohafield,label from koha_attr where 
attr<>''");
+       $sth->execute;
+       my @authorised_values;
+       #push @authorised_values,"";
+       while ((my $kohafield,$label) = $sth->fetchrow_array) {
+               push @authorised_values, $kohafield;
+               push @authorised_labels, $label;
+       }
+       my $recordlist  = CGI::scrolling_list(-name=>'kohafield',
+                       -values=> address@hidden,
+                       -labels=>address@hidden,
+                       -size=>1,
+                       -multiple=>0,
+                       -default => $data->{'kohafield'},
+                       );
+       
+       if ($searchfield) {
+               $template->param(action => "Modify tag",id=>$id ,searchfield => 
"<input type=\"hidden\" name=\"kohafield\" value=\"$searchfield\" 
/>$searchfield");
+               $template->param('heading-modify-tag-p' => 1);
+       } else {
+               $template->param(action => "Add tag",
+                                                               searchfield => 
"<input type=\"text\" name=\"kohafield\" size=\"40\" maxlength=\"80\" />");
+               $template->param('heading-add-tag-p' => 1);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(label => $data->{'label'},
+                       attr=> $data->{'attr'},
+                       recordtype=>$recordlist,
+                       tagfield=>$taglist,
+                       tagsubfield=>$tagsublist,
+                       sorts => CGI::checkbox(-name=>'sorts',
+                                       -checked=> 
$data->{'sorts'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'sorts'),
+                       opacshow => CGI::checkbox(-name=>'opacshow',
+                                               -checked=> 
$data->{'opacshow'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'opacshow'),
+                       intrashow => CGI::checkbox(-name=>'intrashow',
+                                               -checked=> 
$data->{'intrashow'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'intrashow'),
+
+
+                       );
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+my $id       =$input->param('id');
+
+       $sth=$dbh->prepare("replace koha_attr  set 
id=?,kohafield=?,attr=?,label=?,sorts=?,recordtype=?,tagfield=?,tagsubfield=? 
,opacshow=?,intrashow=? ");
+
+       
+       my $kohafield       =$input->param('kohafield');
+       my $attr       =$input->param('attr');
+       my $label  = $input->param('label');
+       my $sorts =$input->param('sorts');
+       my $opacshow =$input->param('opacshow');
+       my $intrashow =$input->param('intrashow');
+       my $recordtype =$input->param('recordtype');
+       my $tagfield =$input->param('tagfield');
+       my $tagsubfield =$input->param('tagsubfield');
+       unless (C4::Context->config('demo') eq 1) {
+               $sth->execute( 
$id,$kohafield,$attr,$label,$sorts?1:0,$recordtype,$tagfield,$tagsubfield,$opacshow?1:0,$intrashow?1:0);
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=koha_attr.pl?searchfield=$kohafield\"></html>";
+
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $sth=$dbh->prepare("select id,kohafield,label,recordtype from koha_attr 
where id=? ");
+               $sth->execute($id);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(label => $data->{'label'}."/". 
$data->{'recordtype'},id=>$data->{'id'},
+                                                       searchfield => 
$searchfield,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+
+       unless (C4::Context->config('demo') eq 1) {
+               $dbh->do("delete from koha_attr where id=$id ");
+       }
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+
+################## DEFAULT ##################################
+} else { # DEFAULT
+       # here, $op can be unset or set 
+       if  ($searchfield ne '') {
+                $template->param(searchfield => $searchfield);
+       }
+       my $cnt=0;
+       if ($dspchoice) {
+               #here, user only wants used tags/subfields displayed
+               my $sth=$dbh->prepare("Select * from koha_attr where tagfield 
<>'' and kohafield >= ? ");
+               #could be ordoned by tab
+               $sth->execute($searchfield);
+
+               while (my $data=$sth->fetchrow_hashref){
+                       push(@results,$data);
+                       $cnt++;
+               }
+
+               $sth->finish;
+               
+               my $toggle=0;
+               my @loop_data = ();
+               my $j=1;
+               my $i=$offset;
+               while ($i < ($offset+$pagesize<$cnt?$offset+$pagesize:$cnt)) {
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{id} = $results[$i]->{'id'};
+                       $row_data{kohafield} = $results[$i]->{'kohafield'};
+                       $row_data{label} = $results[$i]->{'label'};
+                       $row_data{sorts} = $results[$i]->{'sorts'};
+                       $row_data{attr} = $results[$i]->{'attr'};
+                       $row_data{recordtype} = $results[$i]->{'recordtype'};
+                       $row_data{tagfield} = $results[$i]->{'tagfield'};
+                       $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
+                       $row_data{opacshow} = $results[$i]->{'opacshow'};
+                       $row_data{intrashow} = $results[$i]->{'intrashow'};
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{toggle} = $toggle;
+                       push(@loop_data, \%row_data);
+                       $i++;
+               }
+               $template->param(select_display => "True",
+                                               loop => address@hidden);
+               $sth->finish;
+       } else {
+               #here, normal old style : display every tags
+               my ($count,@results)=StringSearch($dbh,$searchfield);
+               $cnt = $count;
+               my $toggle=0;
+               my @loop_data = ();
+               for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{id} = $results[$i]->{'id'};
+                       $row_data{kohafield} = $results[$i]->{'kohafield'};
+                       $row_data{label} = $results[$i]->{'label'};
+                       $row_data{sorts} = $results[$i]->{'sorts'};
+                       $row_data{attr} = $results[$i]->{'attr'};
+                       $row_data{recordtype} = $results[$i]->{'recordtype'};
+                       $row_data{tagfield} = $results[$i]->{'tagfield'};
+                       $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
+                       $row_data{opacshow} = $results[$i]->{'opacshow'};
+                       $row_data{intrashow} = $results[$i]->{'intrashow'};
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{toggle} = $toggle;
+                       push(@loop_data, \%row_data);
+               }
+               $template->param(loop => address@hidden);
+       }
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(isprevpage => $offset,
+                                               prevpage=> $prevpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               
+               );
+       }
+       if ($offset+$pagesize<$cnt) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(nextpage =>$nextpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               
+               );
+       }
+} #---- END $OP eq DEFAULT
+
+$template->param(loggeninuser => $loggedinuser,
+               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+#
+# the sub used for searches
+#
+sub StringSearch  {
+       my ($dbh,$searchstring)address@hidden;
+       my $sth=$dbh->prepare("Select * from koha_attr  where kohafield >=?  
order by kohafield");
+       $sth->execute($searchstring);
+       my @dataresults;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@dataresults,$data);
+
+       }
+
+       $sth->finish;
+       return (scalar(@dataresults),@dataresults);
+}
+
+
+

Index: holdings_subfields_structure.pl
===================================================================
RCS file: holdings_subfields_structure.pl
diff -N holdings_subfields_structure.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ holdings_subfields_structure.pl     25 Mar 2007 23:14:17 -0000      1.1.2.2
@@ -0,0 +1,458 @@
+#!/usr/bin/perl
+
+
+# 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 C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Auth;
+use CGI;
+use C4::Search;
+use C4::Context;
+
+
+sub StringSearch  {
+       my ($env,$searchstring,$frameworkcode)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from holdings_subfield_structure where 
(tagfield like ? and frameworkcode=?) order by tagfield");
+       $sth->execute("$searchstring%",$frameworkcode);
+       my @results;
+       my $cnt=0;
+       my $u=1;
+       while (my $data=$sth->fetchrow_hashref){
+               push(@results,$data);
+               $cnt ++;
+               $u++;
+       }
+       $sth->finish;
+       $dbh->disconnect;
+       return ($cnt,address@hidden);
+}
+
+my $input = new CGI;
+my $tagfield=$input->param('tagfield');
+my $tagsubfield=$input->param('tagsubfield');
+my $frameworkcode=$input->param('frameworkcode');
+my $pkfield="tagfield";
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/holdings_subfields_structure.pl";
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => 
"admin/holdings_subfields_structure.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+my $pagesize=30;
+my $op = $input->param('op');
+$tagfield=~ s/\,//g;
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               tagfield =>$tagfield,
+                                               frameworkcode => $frameworkcode,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               tagfield =>$tagfield,
+                                               frameworkcode => $frameworkcode,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       my $data;
+       my $dbh = C4::Context->dbh;
+       my $more_subfields = $input->param("more_subfields")+1;
+       
+       
+       # build authorised value list
+       
+my     $sth2 = $dbh->prepare("select distinct category from 
authorised_values");
+       $sth2->execute;
+       my @authorised_values;
+       push @authorised_values,"";
+       while ((my $category) = $sth2->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       push (@authorised_values,"branches");
+       push (@authorised_values,"itemtypes");
+       # build thesaurus categories list
+       $sth2->finish;
+       $sth2 = $dbh->prepare("select authtypecode from auth_types");
+       $sth2->execute;
+       my @authtypes;
+       push @authtypes,"";
+       while ((my $authtypecode) = $sth2->fetchrow_array) {
+               push @authtypes, $authtypecode;
+       }
+       # build value_builder list
+       my @value_builder=('');
+
+       # read value_builder directory.
+       # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
+       # on a standard install, /cgi-bin need to be added. 
+       # test one, then the other
+       my $cgidir = C4::Context->intranetdir ."/cgi-bin";
+       unless (opendir(DIR, "$cgidir/value_builder")) {
+               $cgidir = C4::Context->intranetdir;
+               opendir(DIR, "$cgidir/value_builder") || die "can't opendir 
$cgidir/value_builder: $!";
+       } 
+       while (my $line = readdir(DIR)) {
+               if ($line =~ /\.pl$/) {
+                       push (@value_builder,$line);
+               }
+       }
+       closedir DIR;
+
+       # build values list
+       my $sth=$dbh->prepare("select * from holdings_subfield_structure where 
tagfield=? and frameworkcode=?"); # and tagsubfield='$tagsubfield'");
+       $sth->execute($tagfield,$frameworkcode);
+       my @loop_data = ();
+       my $toggle=1;
+       my $i=0;
+       while ($data =$sth->fetchrow_hashref) {
+               my %row_data;  # get a fresh hash for the row data
+               if ($toggle eq 1){
+                       $toggle=0;
+               } else {
+                       $toggle=1;
+               }
+               $row_data{tab} = CGI::scrolling_list(-name=>'tab',
+                                       -id=>"tab$i",
+                                       -values=>['-1','10'],
+                                       -labels => {'-1' 
=>'ignore','10'=>'items (10)', },
+                                       -default=>$data->{'tab'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
+                                       -id=>"ohidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>substr($data->{'hidden'},0,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
+                                       -id=>"ihidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>substr($data->{'hidden'},1,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
+                                       -id=>"ehidden$i",
+                                       -values=>['0','1','2'],
+                                       -labels => {'0'=>'Show','1'=>'Show 
Collapsed',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>substr($data->{'hidden'},2,1),
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{tagsubfield} =$data->{'tagsubfield'}."<input 
type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" 
id=\"tagsubfield\">";
+               $row_data{liblibrarian} = 
CGI::escapeHTML($data->{'liblibrarian'});
+               $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
+               $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
+               
+               $row_data{authorised_value}  = 
CGI::scrolling_list(-name=>'authorised_value',
+                                       -id=>'authorised_value',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'authorised_value'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{value_builder}  = 
CGI::scrolling_list(-name=>'value_builder',
+                                       -id=>'value_builder',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'value_builder'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{authtypes}  = 
CGI::scrolling_list(-name=>'authtypecode',
+                                       -id=>'authtypecode',
+                                       -values=> address@hidden,
+                                       -default=>$data->{'authtypecode'},
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{repeatable} = CGI::checkbox(-name=>"repeatable$i",
+       -checked => $data->{'repeatable'}?'checked':'',
+       -value => 1,
+       -label => '',
+       -id => "repeatable$i");
+               $row_data{mandatory} = CGI::checkbox(-name => "mandatory$i",
+       -checked => $data->{'mandatory'}?'checked':'',
+       -value => 1,
+       -label => '',
+       -id => "mandatory$i");
+               $row_data{hidden} = CGI::escapeHTML($data->{hidden});
+               $row_data{isurl} = CGI::checkbox( -name => "isurl$i",
+                       -id => "isurl$i",
+                       -checked => $data->{'isurl'}?'checked':'',
+                       -value => 1,
+                       -label => '');
+               $row_data{row} = $i;
+               $row_data{toggle} = $toggle;
+               $row_data{link} = CGI::escapeHTML($data->{'link'});
+               push(@loop_data, \%row_data);
+               $i++;
+       }
+       # add more_subfields empty lines for add if needed
+       for (my $i=1;$i<=$more_subfields;$i++) {
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{tab} = CGI::scrolling_list(-name=>'tab',
+                                       -id => "tab$i",
+                                       -values=>['-1','10'],
+                                       -labels => {'-1' 
=>'ignore','10'=>'items (10)',},
+                                       -default=>"",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
+                                       -id=>"ohidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
+                                       -id=>"ihidden$i",
+                                       -values=>['0','2'],
+                                       -labels => {'0'=>'Show','2' =>'Hide',},
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
+                                       -id=>"ehidden$i",
+                                       -values=>['0','1','2'],
+                                       -labels => {'0'=>'Show','1'=>'Show 
Collapsed',
+                                                                       '2' 
=>'Hide',
+                                                                       },
+                                       -default=>"0",
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{tagsubfield} = "<input type=\"text\" 
name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" 
id=\"tagsubfield\" maxlength=\"1\">";
+               $row_data{liblibrarian} = "";
+               $row_data{libopac} = "";
+               $row_data{seealso} = "";
+               $row_data{hidden} = "000";
+               $row_data{repeatable} = CGI::checkbox( -name=> 'repeatable',
+                               -id => "repeatable$i",
+                               -checked => '',
+                               -value => 1,
+                               -label => '');
+               $row_data{mandatory} = CGI::checkbox( -name=> 'mandatory',
+                       -id => "mandatory$i",
+                       -checked => '',
+                       -value => 1,
+                       -label => '');
+               $row_data{isurl} = CGI::checkbox(-name => 'isurl',
+                       -id => "isurl$i",
+                       -checked => '',
+                       -value => 1,
+                       -label => '');
+               
+               $row_data{authorised_value}  = 
CGI::scrolling_list(-name=>'authorised_value',
+                                       -id => 'authorised_value',
+                                       -values=> address@hidden,
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{authtypes}  = 
CGI::scrolling_list(-name=>'authtypecode',
+                                       -id => 'authtypecode',
+                                       -values=> address@hidden,
+                                       -size=>1,
+                                       -multiple=>0,
+                                       );
+               $row_data{link} = CGI::escapeHTML($data->{'link'});
+               $row_data{toggle} = $toggle;
+               $row_data{row} = $i;
+               push(@loop_data, \%row_data);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param('heading-edit-subfields-p' => 1);
+       $template->param(action => "Edit subfields",
+                                                       tagfield => "<input 
type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
+                                                       loop => address@hidden,
+                                                       more_subfields => 
$more_subfields,
+                                                       more_tag => $tagfield);
+
+                                                                               
                # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       $template->param(tagfield => "$input->param('tagfield')");
+       my $sth=$dbh->prepare("replace holdings_subfield_structure 
(tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode,
 link)
+                                                                       values 
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+       my @tagsubfield = $input->param('tagsubfield');
+       my @liblibrarian        = $input->param('liblibrarian');
+       my @libopac             = $input->param('libopac');
+       
+       my @tab                         = $input->param('tab');
+       my @seealso             = $input->param('seealso');
+#      my @hidden              = $input->param('hidden');
+       my @hidden;
+       my @ohidden             = $input->param('ohidden');
+       my @ihidden             = $input->param('ihidden');
+       my @ehidden             = $input->param('ehidden');
+       my @authorised_values   = $input->param('authorised_value');
+       my @authtypecodes       = $input->param('authtypecode');
+       my @value_builder       =$input->param('value_builder');
+       my @link                =$input->param('link');
+       for (my $i=0; $i<= $#tagsubfield ; $i++) {
+               my $tagfield                    =$input->param('tagfield');
+               my $tagsubfield         =$tagsubfield[$i];
+               $tagsubfield="@" unless $tagsubfield ne '';
+               my $liblibrarian                =$liblibrarian[$i];
+               my $libopac                     =$libopac[$i];
+               my $repeatable          =$input->param("repeatable$i")?1:0;
+               my $mandatory           =$input->param("mandatory$i")?1:0;
+               
+               my $tab                         =$tab[$i];
+               my $seealso                             =$seealso[$i];
+               my $authorised_value            =$authorised_values[$i];
+               my $authtypecode                =$authtypecodes[$i];
+               my $value_builder=$value_builder[$i];
+               my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate 
from 3 hiddens;
+               my $isurl = $input->param("isurl$i")?1:0;
+               my $link = $link[$i];
+               if ($liblibrarian) {
+                       unless (C4::Context->config('demo') eq 1) {
+                               $sth->execute ($tagfield,
+                                                                       
$tagsubfield,
+                                                                       
$liblibrarian,
+                                                                       
$libopac,
+                                                                       
$repeatable,
+                                                                       
$mandatory,
+                                                                       
+                                                                       $tab,
+                                                                       
$seealso,
+                                                                       
$authorised_value,
+                                                                       
$authtypecode,
+                                                                       
$value_builder,
+                                                                       $hidden,
+                                                                       $isurl,
+                                                                       
$frameworkcode,
+
+        $link,
+                                             );
+                       }
+               }
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=holdings_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+       exit;
+
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select * from holdings_subfield_structure where 
tagfield=? and tagsubfield=? and frameworkcode=?");
+       #FIXME : called with 2 bind variables when 3 are needed
+       $sth->execute($tagfield,$tagsubfield);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                                                       tagsubfield => 
$data->{'tagsubfield'},
+                                                       delete_link => 
$script_name,
+                                                       tagfield      
=>$tagfield,
+                                                       tagsubfield => 
$tagsubfield,
+                                                       frameworkcode => 
$frameworkcode,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       my $dbh = C4::Context->dbh;
+       unless (C4::Context->config('demo') eq 1) {
+               my $sth=$dbh->prepare("delete from holdings_subfield_structure 
where tagfield=? and tagsubfield=? and frameworkcode=?");
+               $sth->execute($tagfield,$tagsubfield,$frameworkcode);
+               $sth->finish;
+       }
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=holdings_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+       exit;
+       $template->param(tagfield => $tagfield);
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       my $env;
+       my ($count,$results)=StringSearch($env,$tagfield,$frameworkcode);
+       my $toggle=1;
+       my @loop_data = ();
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               if ($toggle eq 1){
+                       $toggle=0;
+               } else {
+                       $toggle=1;
+               }
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{tagfield} = $results->[$i]{'tagfield'};
+               $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
+               $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
+               
+               $row_data{repeatable} = $results->[$i]{'repeatable'};
+               $row_data{mandatory} = $results->[$i]{'mandatory'};
+               $row_data{tab} = $results->[$i]{'tab'};
+               $row_data{seealso} = $results->[$i]{'seealso'};
+               $row_data{authorised_value} = 
$results->[$i]{'authorised_value'};
+               $row_data{authtypecode} = $results->[$i]{'authtypecode'};
+               $row_data{value_builder}        = 
$results->[$i]{'value_builder'};
+               $row_data{hidden}       = $results->[$i]{'hidden'} 
if($results->[$i]{'hidden'} gt "000") ;
+               $row_data{isurl}        = $results->[$i]{'isurl'};
+               $row_data{link} = $results->[$i]{'link'};
+               $row_data{delete} = 
"$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&frameworkcode=$frameworkcode";
+               $row_data{toggle} = $toggle;
+               if ($row_data{tab} eq -1) {
+                       $row_data{subfield_ignored} = 1;
+               }
+
+               push(@loop_data, \%row_data);
+       }
+       $template->param(loop => address@hidden);
+       $template->param(edit_tagfield => $tagfield,
+               edit_frameworkcode => $frameworkcode);
+       
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(prev =>"<a 
href=\"$script_name?offset=$prevpage\">");
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(next => "<a 
href=\"$script_name?offset=$nextpage\">");
+       }
+} #---- END $OP eq DEFAULT
+$template->param(intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;

Index: holdingstagstructure.pl
===================================================================
RCS file: holdingstagstructure.pl
diff -N holdingstagstructure.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ holdingstagstructure.pl     25 Mar 2007 23:14:17 -0000      1.1.2.2
@@ -0,0 +1,366 @@
+#!/usr/bin/perl
+
+
+# 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::Auth;
+use C4::Koha;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+
+
+# retrieve parameters
+my $input = new CGI;
+my $frameworkcode = $input->param('frameworkcode'); # set to select framework
+$frameworkcode="" unless $frameworkcode;
+my $existingframeworkcode = $input->param('existingframeworkcode'); # set when 
we have to create a new framework (in frameworkcode) by copying an old one (in 
existingframeworkcode)
+$existingframeworkcode = "" unless $existingframeworkcode;
+my $frameworkinfo = getframeworkinfo($frameworkcode);
+my $searchfield=$input->param('searchfield');
+$searchfield=0 unless $searchfield;
+$searchfield=~ s/\,//g;
+
+my $offset=$input->param('offset');
+my $op = $input->param('op');
+my $dspchoice = $input->param('select_display');
+my $pagesize=20;
+
+my $script_name="/cgi-bin/koha/admin/holdingstagstructure.pl";
+
+my $dbh = C4::Context->dbh;
+
+# open template
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => 
"admin/holdingstagstructure.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+# get framework list
+my $frameworks = getframeworks();
+my @frameworkloop;
+foreach my $thisframeworkcode (keys %$frameworks) {
+       my $selected = 1 if $thisframeworkcode eq $frameworkcode;
+       my %row =(value => $thisframeworkcode,
+                               selected => $selected,
+                               frameworktext => 
$frameworks->{$thisframeworkcode}->{'frameworktext'},
+                       );
+       push @frameworkloop, \%row;
+}
+
+# check that framework is defined in holdings_tag_structure
+my $sth=$dbh->prepare("select count(*) from holdings_tag_structure where 
frameworkcode=?");
+$sth->execute($frameworkcode);
+my ($frameworkexist) = $sth->fetchrow;
+if ($frameworkexist) {
+} else {
+       # if frameworkcode does not exists, then OP must be changed to "create 
framework" if we are not on the way to create it
+       # (op = itemtyp_create_confirm)
+       if ($op eq "framework_create_confirm") {
+               duplicate_framework($frameworkcode, $existingframeworkcode);
+               $op=""; # unset $op to go back to framework list
+       } else {
+               $op = "framework_create";
+       }
+}
+$template->param(frameworkloop => address@hidden,
+                               frameworkcode => $frameworkcode,
+                               frameworktext => 
$frameworkinfo->{frameworktext});
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               $sth=$dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
holdings_tag_structure where tagfield=? and frameworkcode=?");
+               $sth->execute($searchfield,$frameworkcode);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       my $sth = $dbh->prepare("select distinct category from 
authorised_values");
+       $sth->execute;
+       my @authorised_values;
+       push @authorised_values,"";
+       while ((my $category) = $sth->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       my $authorised_value  = CGI::scrolling_list(-name=>'authorised_value',
+                       -values=> address@hidden,
+                       -size=>1,
+                       -id=>"authorised_value",
+                       -multiple=>0,
+                       -default => $data->{'authorised_value'},
+                       );
+
+       if ($searchfield) {
+               $template->param(action => "Modify tag",
+                                                               searchfield => 
"<input type=\"hidden\" name=\"tagfield\" value=\"$searchfield\" 
/>$searchfield");
+               $template->param('heading-modify-tag-p' => 1);
+       } else {
+               $template->param(action => "Add tag",
+                                                               searchfield => 
"<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
+               $template->param('heading-add-tag-p' => 1);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                       libopac => $data->{'libopac'},
+                       repeatable => CGI::checkbox(-name=>'repeatable',
+                                               -checked=> 
$data->{'repeatable'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'repeatable'),
+                       mandatory => CGI::checkbox(-name => 'mandatory',
+                                               -checked => 
$data->{'mandatory'}?'checked':'',
+                                               -value => 1,
+                                               -label => '',
+                                               -id => 'mandatory'),
+                       authorised_value => $authorised_value,
+                       frameworkcode => $frameworkcode,
+                       );
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $sth=$dbh->prepare("replace holdings_tag_structure 
(tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,frameworkcode)
 values (?,?,?,?,?,?,?)");
+       my $tagfield       =$input->param('tagfield');
+       my $liblibrarian  = $input->param('liblibrarian');
+       my $libopac       =$input->param('libopac');
+       my $repeatable =$input->param('repeatable');
+       my $mandatory =$input->param('mandatory');
+       my $authorised_value =$input->param('authorised_value');
+       unless (C4::Context->config('demo') eq 1) {
+               $sth->execute($tagfield,
+                                                       $liblibrarian,
+                                                       $libopac,
+                                                       $repeatable?1:0,
+                                                       $mandatory?1:0,
+                                                       $authorised_value,
+                                                       $frameworkcode
+                                                       );
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=holdingstagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $sth=$dbh->prepare("select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
holdings_tag_structure where tagfield=? and frameworkcode=?");
+       $sth->execute($searchfield,$frameworkcode);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(liblibrarian => $data->{'liblibrarian'},
+                                                       searchfield => 
$searchfield,
+                                                       frameworkcode => 
$frameworkcode,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       unless (C4::Context->config('demo') eq 1) {
+               $dbh->do("delete from holdings_tag_structure where 
tagfield='$searchfield' and frameworkcode='$frameworkcode'");
+               $dbh->do("delete from holdings_subfield_structure where 
tagfield='$searchfield' and frameworkcode='$frameworkcode'");
+
+       }
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## ITEMTYPE_CREATE ##################################
+# called automatically if an unexisting  frameworkis selected
+} elsif ($op eq 'framework_create') {
+       $sth = $dbh->prepare("select 
count(*),holdings_tag_structure.frameworkcode,frameworktext from 
holdings_tag_structure,biblio_framework where 
biblio_framework.frameworkcode=holdings_tag_structure.frameworkcode group by 
holdings_tag_structure.frameworkcode");
+       $sth->execute;
+       my @existingframeworkloop;
+       while (my ($tot,$thisframeworkcode,$frameworktext) = $sth->fetchrow) {
+               if ($tot>0) {
+                       my %line = ( value => $thisframeworkcode,
+                                               frameworktext => $frameworktext,
+                                       );
+                       push @existingframeworkloop,\%line;
+               }
+       }
+       $template->param(existingframeworkloop => address@hidden,
+                                       frameworkcode => $frameworkcode,
+#                                      FRtext => 
$frameworkinfo->{frameworktext},
+                                       );
+################## DEFAULT ##################################
+} else { # DEFAULT
+       # here, $op can be unset or set to "framework_create_confirm".
+       if  ($searchfield ne '') {
+                $template->param(searchfield => $searchfield);
+       }
+       my $cnt=0;
+       if ($dspchoice) {
+               #here, user only wants used tags/subfields displayed
+               my $env;
+               $searchfield=~ s/\'/\\\'/g;
+               my @data=split(' ',$searchfield);
+               my $sth=$dbh->prepare("Select holdings_tag_structure.tagfield 
as mts_tagfield,holdings_tag_structure.liblibrarian as 
mts_liblibrarian,holdings_tag_structure.libopac as 
mts_libopac,holdings_tag_structure.repeatable as 
mts_repeatable,holdings_tag_structure.mandatory as 
mts_mandatory,holdings_tag_structure.authorised_value as 
mts_authorized_value,holdings_subfield_structure.* from holdings_tag_structure 
LEFT JOIN holdings_subfield_structure ON 
(holdings_tag_structure.tagfield=holdings_subfield_structure.tagfield AND 
holdings_tag_structure.frameworkcode=holdings_subfield_structure.frameworkcode) 
where (holdings_tag_structure.tagfield >= ? and 
holdings_tag_structure.frameworkcode=?) AND holdings_subfield_structure.tab>=0 
order by 
holdings_tag_structure.tagfield,holdings_subfield_structure.tagsubfield");
+               #could be ordoned by tab
+               $sth->execute($data[0], $frameworkcode);
+               my @results = ();
+               while (my $data=$sth->fetchrow_hashref){
+                       push(@results,$data);
+                       $cnt++;
+               }
+               $sth->finish;
+               
+               my $toggle=0;
+               my @loop_data = ();
+               my $j=1;
+               my $i=$offset;
+               while ($i < ($offset+$pagesize<$cnt?$offset+$pagesize:$cnt)) {
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{tagfield} = $results[$i]->{'mts_tagfield'};
+                       $row_data{liblibrarian} = 
$results[$i]->{'mts_liblibrarian'};
+                       $row_data{repeatable} = 
$results[$i]->{'mts_repeatable'};
+                       $row_data{mandatory} = $results[$i]->{'mts_mandatory'};
+                       $row_data{authorised_value} = 
$results[$i]->{'mts_authorised_value'};
+                       $row_data{subfield_link} 
="holdings_subfields_structure.pl?op=add_form&tagfield=".$results[$i]->{'mts_tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results[$i]->{'mts_tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'mts_tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{toggle} = $toggle;
+                       $j=$i;
+                       my @internal_loop = ();
+                       while 
(($results[$i]->{'tagfield'}==$results[$j]->{'tagfield'}) and ($j< 
($offset+$pagesize<$cnt?$offset+$pagesize:$cnt))) {
+                               if ($toggle eq 0) {
+                                       $toggle=1;
+                               } else {
+                                       $toggle=0;
+                               }
+                               my %subfield_data;
+                               $subfield_data{tagsubfield} = 
$results[$j]->{'tagsubfield'};
+                               $subfield_data{liblibrarian} = 
$results[$j]->{'liblibrarian'};
+                               
+                               $subfield_data{repeatable} = 
$results[$j]->{'repeatable'};
+                               $subfield_data{mandatory} = 
$results[$j]->{'mandatory'};
+                               $subfield_data{tab} = $results[$j]->{'tab'};
+                               $subfield_data{seealso} = 
$results[$j]->{'seealso'};
+                               $subfield_data{authorised_value} = 
$results[$j]->{'authorised_value'};
+                               $subfield_data{authtypecode}= 
$results[$j]->{'authtypecode'};
+                               $subfield_data{value_builder}= 
$results[$j]->{'value_builder'};
+                               $subfield_data{toggle}  = $toggle;
+#                              warn "tagfield :  
".$results[$j]->{'tagfield'}." tagsubfield :".$results[$j]->{'tagsubfield'};
+                               push @internal_loop,\%subfield_data;
+                               $j++;
+                       }
+                       $row_data{'subfields'address@hidden;
+                       push(@loop_data, \%row_data);
+#                      undef @internal_loop;
+                       $i=$j;
+               }
+               $template->param(select_display => "True",
+                                               loop => address@hidden);
+               #  $sth->execute;
+               $sth->finish;
+       } else {
+               #here, normal old style : display every tags
+               my $env;
+               my 
($count,$results)=StringSearch($env,$searchfield,$frameworkcode);
+               $cnt = $count;
+               my $toggle=0;
+               my @loop_data = ();
+               for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{tagfield} = $results->[$i]{'tagfield'};
+                       $row_data{liblibrarian} = 
$results->[$i]{'liblibrarian'};
+                       $row_data{repeatable} = $results->[$i]{'repeatable'};
+                       $row_data{mandatory} = $results->[$i]{'mandatory'};
+                       $row_data{authorised_value} = 
$results->[$i]{'authorised_value'};
+                       $row_data{subfield_link} 
="holdings_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results->[$i]{'tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'tagfield'}."&frameworkcode=".$frameworkcode;
+                       $row_data{toggle} = $toggle;
+                       push(@loop_data, \%row_data);
+               }
+               $template->param(loop => address@hidden);
+       }
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(isprevpage => $offset,
+                                               prevpage=> $prevpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               frameworkcode => $frameworkcode,
+               );
+       }
+       if ($offset+$pagesize<$cnt) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(nextpage =>$nextpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               frameworkcode => $frameworkcode,
+               );
+       }
+} #---- END $OP eq DEFAULT
+
+$template->param(loggeninuser => $loggedinuser,
+               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+#
+# the sub used for searches
+#
+sub StringSearch  {
+       my ($env,$searchstring,$frameworkcode)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select 
tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from 
holdings_tag_structure where (tagfield >= ? and frameworkcode=?) order by 
tagfield");
+       $sth->execute($data[0], $frameworkcode);
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+#
+
+

Index: institutions-careers.pl
===================================================================
RCS file: institutions-careers.pl
diff -N institutions-careers.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ institutions-careers.pl     25 Mar 2007 23:14:17 -0000      1.1.2.2
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+# Script to manage the educational institutions and its careers.
+# written 12/04
+# CastaƱeda, Carlos Sebastian - address@hidden - Physics Library UNLP Argentina
+
+# 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::Auth;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::AcademicInfo;
+
+my $cgi = new CGI;
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => 
"admin/institutions-careers.tmpl",
+                            query => $cgi,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {editcatalogue => 1},
+                            debug => 1,
+                            });
+
+my $op = $cgi->param('op'); 
+my $id_institution = $cgi->param('id_institution'); 
+my $institution_name = $cgi->param('institution_name'); 
+
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       
+       if ($id_institution) {
+               my $info = get_educational_institution($id_institution);
+               $template->param(op => 'edit');
+               $template->param(institution_name => 
$info->{'institution_name'});
+               $template->param(id_institution => $id_institution);
+       } else {
+               $template->param(op => 'add');
+       }
+
+} elsif ($op eq 'add') {
+       add_educational_institution($institution_name);
+       print $cgi->redirect('/cgi-bin/koha/admin/institutions-careers.pl');
+} elsif ($op eq 'edit') {
+       update_educational_institution($id_institution, $institution_name);
+       print $cgi->redirect('/cgi-bin/koha/admin/institutions-careers.pl');
+} elsif ($op eq 'del') {
+       del_educational_institution($id_institution);
+       print $cgi->redirect('/cgi-bin/koha/admin/institutions-careers.pl');
+} else {
+       my @educ_institutions = &get_careers_by_institution();
+       $template->param(institutions => address@hidden);
+}
+
+output_html_with_http_headers $cgi, $cookie, $template->output;

Index: issuingrules.pl
===================================================================
RCS file: issuingrules.pl
diff -N issuingrules.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ issuingrules.pl     25 Mar 2007 23:14:17 -0000      1.11.2.2
@@ -0,0 +1,186 @@
+#!/usr/bin/perl
+
+# 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::Interface::CGI::Output;
+
+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/issuingrules.tmpl",
+                             query => $input,
+                             type => "intranet",
+                             authnotrequired => 0,
+                            flagsrequired => {parameters => 1, management => 
1},
+                             debug => 1,
+                             });
+# save the values entered
+if ($op eq 'save') {
+       my @names=$input->param();
+       my $sth_search = $dbh->prepare("select count(*) as total from 
issuingrules where branchcode=? and categorycode=? and itemtype=?");
+
+       my $sth_Finsert = $dbh->prepare("insert into issuingrules 
(branchcode,categorycode,itemtype,fine,firstremind,chargeperiod) values 
(?,?,?,?,?,?)");
+       my $sth_Fupdate=$dbh->prepare("Update issuingrules set 
fine=?,firstremind=?,chargeperiod=? where branchcode=? and categorycode=? and 
itemtype=?");
+       my $sth_Fdelete=$dbh->prepare("delete from issuingrules where 
branchcode=? and categorycode=? and itemtype=? and issuelength=0");
+
+       my $sth_Iinsert = $dbh->prepare("insert into issuingrules 
(branchcode,categorycode,itemtype,maxissueqty,issuelength) values (?,?,?,?,?)");
+       my $sth_Iupdate=$dbh->prepare("Update issuingrules set maxissueqty=?, 
issuelength=? where branchcode=? and categorycode=? and itemtype=?");
+       my $sth_Idelete=$dbh->prepare("delete from issuingrules where 
branchcode=? and categorycode=? and itemtype=? and fine=0");
+       foreach my $key (@names){
+               # ISSUES
+               if ($key =~ /I-(.*)-(.*)\.(.*)/) {
+                       my $br = $1; # branch
+                       my $bor = $2; # borrower category
+                       my $cat = $3; # item type
+                       my $data=$input->param($key);
+                       my ($issuelength,$maxissueqty)=split(',',$data);
+#                      if ($maxissueqty >0) {
+                               $sth_search->execute($br,$bor,$cat);
+                               my $res = $sth_search->fetchrow_hashref();
+                               if ($res->{total}) {
+                                       
$sth_Iupdate->execute($maxissueqty,$issuelength,$br,$bor,$cat);
+                               } else {
+                                       
$sth_Iinsert->execute($br,$bor,$cat,$maxissueqty,$issuelength);
+                               }
+#                      } else {
+#                              $sth_Idelete->execute($br,$bor,$cat);
+#                      }
+               }
+               # FINES
+               if ($key =~ /F-(.*)-(.*)\.(.*)/) {
+                       my $br = $1; # branch
+                       my $bor = $2; # borrower category
+                       my $cat = $3; # item type
+                       my $data=$input->param($key);
+                       my ($fine,$firstremind,$chargeperiod)=split(',',$data);
+#                      if ($fine >0) {
+                               $sth_search->execute($br,$bor,$cat);
+                               my $res = $sth_search->fetchrow_hashref();
+                               if ($res->{total}) {
+                                       
$sth_Fupdate->execute($fine,$firstremind,$chargeperiod,$br,$bor,$cat);
+                               } else {
+                                       
$sth_Finsert->execute($br,$bor,$cat,$fine,$firstremind,$chargeperiod);
+                               }
+#                      } else {
+#                              $sth_Fdelete->execute($br,$bor,$cat);
+#                      }
+               }
+       }
+
+}
+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 @trow3;
+my @title_loop;
+# my $i=0;
+while (my $data=$sth->fetchrow_hashref){
+       my %row = (in_title => $data->{'description'});
+       push @title_loop,\%row;
+       push @trow3,$data->{'categorycode'};
+#      $i++;
+}
+
+my %row = (in_title => "*");
+push @title_loop, \%row;
+push @trow3,'*';
+
+$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 $line;
+$line->{itemtype} = "*";
+$line->{description} = "*";
+push @itemtypes,\$line;
+
+foreach my $data (@itemtypes) {
+       my @trow2;
+       my @cell_loop;
+       if ( $toggle eq 1 ) {
+               $toggle = 0;
+       } else {
+               $toggle = 1;
+       }
+       for (my $i=0;$i<=$#trow3;$i++){
+               my $sth2=$dbh->prepare("select * from issuingrules where 
branchcode=? and categorycode=? and itemtype=?");
+               $sth2->execute($branch,$trow3[$i],$$data->{'itemtype'});
+               my $dat=$sth2->fetchrow_hashref;
+               $sth2->finish;
+               my $fine=$dat->{'fine'}+0;
+               my $maxissueqty = $dat->{'maxissueqty'}+0;
+               my $issuelength = $dat->{'issuelength'}+0;
+               my $finesvalue;
+               $finesvalue= 
"$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}" if 
$fine+$dat->{'firstremind'}+$dat->{'chargeperiod'}>0;
+               my $issuingvalue;
+#              if ($maxissueqty>0) {
+                   $issuingvalue = "$issuelength,$maxissueqty" if 
$issuelength+$maxissueqty>0;
+#              }
+#              else {          
+#                  $issuingvalue = "$issuelength, 5";
+#                  $maxissueqty = 5;
+#              }
+               my %row = (finesname=> 
"F-$branch-$trow3[$i].$$data->{'itemtype'}",
+                                       finesvalue => $finesvalue,
+                                       issuingname => 
"I-$branch-$trow3[$i].$$data->{itemtype}",
+                                       issuingvalue => $issuingvalue,
+                                       toggle => $toggle,
+                                       );
+               push @cell_loop,\%row;
+       }
+       my %row = (categorycode => $$data->{description},
+                                       cell =>address@hidden);
+       push @row_loop, \%row;
+}
+
+$sth->finish;
+$template->param(title => address@hidden,
+                                               row => address@hidden,
+                                               branchloop => address@hidden,
+                                               branch => $branch);
+output_html_with_http_headers $input, $cookie, $template->output;

Index: itemtypes.pl
===================================================================
RCS file: itemtypes.pl
diff -N itemtypes.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ itemtypes.pl        25 Mar 2007 23:14:17 -0000      1.25.2.2
@@ -0,0 +1,200 @@
+#!/usr/bin/perl
+# NOTE: 4-character tabs
+
+#script to administer the categories table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+
+# 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::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from itemtypes where (description like 
?) order by itemtype");
+       $sth->execute("$data[0]%");
+       my @results;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return (scalar(@results),address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('description');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/itemtypes.pl";
+my $itemtype=$input->param('itemtype');
+my $pagesize=20;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/itemtypes.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1, management => 
1},
+                            debug => 1,
+                            });
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #start the page and read in includes
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($itemtype) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select 
itemtype,description,renewalsallowed,rentalcharge,notforloan from itemtypes 
where itemtype=?");
+               $sth->execute($itemtype);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       $template->param(itemtype => $itemtype,
+                                                       description => 
$data->{'description'},
+                                                       renewalsallowed => 
$data->{'renewalsallowed'},
+                                                       rentalcharge => 
sprintf("%.2f",$data->{'rentalcharge'}),
+                                                       notforloan => 
$data->{'notforloan'}
+                                                       );
+;
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace itemtypes 
(itemtype,description,renewalsallowed,rentalcharge,notforloan) values 
(?,?,?,?,?)");
+       $sth->execute(
+               $input->param('itemtype'),$input->param('description'),
+               $input->param('renewalsallowed'),$input->param('rentalcharge'),
+               $input->param('notforloan')?1:0);
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=itemtypes.pl\"></html>";
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       #start the page and read in includes
+       my $dbh = C4::Context->dbh;
+
+       # Check both categoryitem and biblioitems, see Bug 199
+       my $total = 0;
+       for my $table ('biblio') {
+          my $sth=$dbh->prepare("select count(*) as total from $table where 
itemtype=?");
+          $sth->execute($itemtype);
+          $total += $sth->fetchrow_hashref->{total};
+          $sth->finish;
+       }
+
+       my $sth=$dbh->prepare("select 
itemtype,description,renewalsallowed,rentalcharge from itemtypes where 
itemtype=?");
+       $sth->execute($itemtype);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+
+       $template->param(itemtype => $itemtype,
+                                                       description => 
$data->{'description'},
+                                                       renewalsallowed => 
$data->{'renewalsallowed'},
+                                                       rentalcharge => 
sprintf("%.2f",$data->{'rentalcharge'}),
+                                                       total => $total);
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       #start the page and read in includes
+       my $dbh = C4::Context->dbh;
+       my $itemtype=uc($input->param('itemtype'));
+       my $sth=$dbh->prepare("delete from itemtypes where itemtype=?");
+       $sth->execute($itemtype);
+       $sth = $dbh->prepare("delete from issuingrules where itemtype=?");
+       $sth->execute($itemtype);
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=itemtypes.pl\"></html>";
+       exit;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my $toggle=0;
+       my @loop_data;
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               my %row_data;
+               if ($toggle eq 0){
+                       $toggle=1;
+               } else {
+                       $toggle=0;
+               }
+               $row_data{toggle} = $toggle;
+               $row_data{itemtype} = $results->[$i]{itemtype};
+               $row_data{description} = $results->[$i]{description};
+               $row_data{renewalsallowed} = $results->[$i]{renewalsallowed};
+               $row_data{notforloan} = $results->[$i]{notforloan};
+               $row_data{rentalcharge} = 
sprintf("%.2f",$results->[$i]{rentalcharge});
+               push(@loop_data, \%row_data);
+       }
+       $template->param(loop => address@hidden);
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(previous => "$script_name?offset=".$prevpage);
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(next => "$script_name?offset=".$nextpage);
+       }
+} #---- END $OP eq DEFAULT
+output_html_with_http_headers $input, $cookie, $template->output;
+
+# Local Variables:
+# tab-width: 4
+# End:

Index: koha-electronic.pl
===================================================================
RCS file: koha-electronic.pl
diff -N koha-electronic.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ koha-electronic.pl  25 Mar 2007 23:14:17 -0000      1.2.2.2
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+
+# Script to manage the opac news.
+# written 11/04
+# CastaƱeda, Carlos Sebastian - address@hidden - Physics Library UNLP Argentina
+
+# 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::Auth;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::NewsChannels;
+
+
+my $cgi = new CGI;
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/koha-electronic.tmpl",
+                            query => $cgi,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+my $op = $cgi->param('op');
+
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       my $id = $cgi->param("id");
+       my $edata;
+# warn "add_form";     
+       if ($id) {
+               $template->param(op => 'edit');
+               $edata = get_opac_electronic($id);
+               $template->param($edata);
+               $template->param(id => $edata->{'idelectronic'});
+       } else {
+               $template->param(op => 'add');
+       }
+       
+} elsif ($op eq 'add') {
+# warn "add";
+       my $title       = $cgi->param('title');
+       my $edata       = $cgi->param('edata');
+       my $lang        = $cgi->param('lang');
+       my $image       = $cgi->param('image');
+       my $href        = $cgi->param('href');
+       my $section     = $cgi->param('section');
+       add_opac_electronic($title, $edata, $lang,$image, $href,$section);
+       print $cgi->redirect('/cgi-bin/koha/admin/koha-electronic.pl');
+
+} elsif ($op eq 'edit') {
+# warn "edit";
+       my $id          = $cgi->param('id');
+       my $title       = $cgi->param('title');
+       my $edata       = $cgi->param('edata');
+       my $lang        = $cgi->param('lang');
+       my $image       = $cgi->param('image');
+       my $href        = $cgi->param('href');
+       my $section     = $cgi->param('section');
+       upd_opac_electronic($id, $title, $edata, $lang,$image,$href,$section);
+       print $cgi->redirect('/cgi-bin/koha/admin/koha-electronic.pl');
+
+} elsif ($op eq 'del') {
+# warn "del";
+       my @ids = $cgi->param('ids');
+       del_opac_electronic(join ",", @ids);
+       print $cgi->redirect('/cgi-bin/koha/admin/koha-electronic.pl');
+
+} else { 
+# warn "else";
+
+       my $lang = $cgi->param('lang');
+
+       my ($opac_electronic_count, $opac_electronic) = 
&get_opac_electronics(undef, $lang);
+       $template->param($lang => 1);
+       $template->param(opac_electronic => $opac_electronic);
+       $template->param(opac_electronic_count => $opac_electronic_count);
+
+}
+
+output_html_with_http_headers $cgi, $cookie, $template->output;

Index: koha_attr.pl
===================================================================
RCS file: koha_attr.pl
diff -N koha_attr.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ koha_attr.pl        25 Mar 2007 23:14:17 -0000      1.3.2.2
@@ -0,0 +1,321 @@
+#!/usr/bin/perl
+
+
+# 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::Auth;
+use C4::Koha;
+use C4::Context;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+
+
+# retrieve parameters
+my $input = new CGI;
+
+my $searchfield=$input->param('searchfield');
+$searchfield="" unless $searchfield;
+my $id=$input->param('id');
+my $offset=$input->param('offset');
+$offset=0 unless $offset;
+my $op = $input->param('op');
+my $dspchoice = $input->param('select_display');
+my $pagesize=20;
+my @results = ();
+my $script_name="/cgi-bin/koha/admin/koha_attr.pl";
+
+my $dbh = C4::Context->dbh;
+my $sth;
+# open template
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/koha_attr.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($id) {
+               $sth=$dbh->prepare("select 
id,kohafield,attr,label,sorts,recordtype,tagfield,tagsubfield,opacshow,intrashow
 from koha_attr where id=? ");
+               $sth->execute($id);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       my $sth = $dbh->prepare("select authorised_value from authorised_values 
where category='recordtype'");
+       $sth->execute;
+       my @authorised_values;
+       #push @authorised_values,"";
+       while ((my $category) = $sth->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       my $recordlist  = CGI::scrolling_list(-name=>'recordtype',
+                       -values=> address@hidden,
+                       -size=>1,
+                       -multiple=>0,
+                       -default => $data->{'recordtype'},
+                       );
+       my $sth = $dbh->prepare("select authorised_value from authorised_values 
where category='mfield' order by lib");
+       $sth->execute;
+       my @authorised_values;
+       #push @authorised_values,"";
+       while ((my $category) = $sth->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       my $taglist  = CGI::scrolling_list(-name=>'tagfield',
+                       -values=> address@hidden,
+                       -size=>1,
+                       -multiple=>0,
+                       -default => $data->{'tagfield'},
+                       );
+       my $sth = $dbh->prepare("select authorised_value from authorised_values 
where category='subfield' order by lib ");
+       $sth->execute;
+       my @authorised_values;
+       #push @authorised_values,"";
+       while ((my $category) = $sth->fetchrow_array) {
+               push @authorised_values, $category;
+       }
+       my $tagsublist  = CGI::scrolling_list(-name=>'tagsubfield',
+                       -values=> address@hidden,
+                       -size=>1,
+                       -multiple=>0,
+                       -default => $data->{'tagsubfield'},
+                       );
+       
+       if ($searchfield) {
+               $template->param(action => "Modify tag",id=>$id ,searchfield => 
"<input type=\"hidden\" name=\"kohafield\" value=\"$searchfield\" 
/>$searchfield");
+               $template->param('heading-modify-tag-p' => 1);
+       } else {
+               $template->param(action => "Add tag",
+                                                               searchfield => 
"<input type=\"text\" name=\"kohafield\" size=\"40\" maxlength=\"80\" />");
+               $template->param('heading-add-tag-p' => 1);
+       }
+       $template->param('use-heading-flags-p' => 1);
+       $template->param(label => $data->{'label'},
+                       attr=> $data->{'attr'},
+                       recordtype=>$recordlist,
+                       tagfield=>$taglist,
+                       tagsubfield=>$tagsublist,
+                       sorts => CGI::checkbox(-name=>'sorts',
+                                       -checked=> 
$data->{'sorts'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'sorts'),
+                       opacshow => CGI::checkbox(-name=>'opacshow',
+                                               -checked=> 
$data->{'opacshow'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'opacshow'),
+                       intrashow => CGI::checkbox(-name=>'intrashow',
+                                               -checked=> 
$data->{'intrashow'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'intrashow'),
+
+
+                       );
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+my $id       =$input->param('id');
+
+       $sth=$dbh->prepare("replace koha_attr  set 
id=?,kohafield=?,attr=?,label=?,sorts=?,recordtype=?,tagfield=?,tagsubfield=? 
,opacshow=?,intrashow=? ");
+
+       
+       my $kohafield       =$input->param('kohafield');
+       my $attr       =$input->param('attr');
+       my $label  = $input->param('label');
+       my $sorts =$input->param('sorts');
+       my $opacshow =$input->param('opacshow');
+       my $intrashow =$input->param('intrashow');
+       my $recordtype =$input->param('recordtype');
+       my $tagfield =$input->param('tagfield');
+       my $tagsubfield =$input->param('tagsubfield');
+       unless (C4::Context->config('demo') eq 1) {
+               $sth->execute( 
$id,$kohafield,$attr,$label,$sorts?1:0,$recordtype,$tagfield,$tagsubfield,$opacshow?1:0,$intrashow?1:0);
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=koha_attr.pl?searchfield=$kohafield\"></html>";
+
+       exit;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $sth=$dbh->prepare("select id,kohafield,label,recordtype from koha_attr 
where id=? ");
+               $sth->execute($id);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(label => $data->{'label'}."/". 
$data->{'recordtype'},id=>$data->{'id'},
+                                                       searchfield => 
$searchfield,
+                                                       );
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+
+       unless (C4::Context->config('demo') eq 1) {
+               $dbh->do("delete from koha_attr where id=$id ");
+       }
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+
+################## DEFAULT ##################################
+} else { # DEFAULT
+       # here, $op can be unset or set 
+       if  ($searchfield ne '') {
+                $template->param(searchfield => $searchfield);
+       }
+       my $cnt=0;
+       if ($dspchoice) {
+               #here, user only wants used tags/subfields displayed
+               my $sth=$dbh->prepare("Select * from koha_attr where tagfield 
<>'' and kohafield >= ? ");
+               #could be ordoned by tab
+               $sth->execute($searchfield);
+
+               while (my $data=$sth->fetchrow_hashref){
+                       push(@results,$data);
+                       $cnt++;
+               }
+
+               $sth->finish;
+               
+               my $toggle=0;
+               my @loop_data = ();
+               my $j=1;
+               my $i=$offset;
+               while ($i < ($offset+$pagesize<$cnt?$offset+$pagesize:$cnt)) {
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{id} = $results[$i]->{'id'};
+                       $row_data{kohafield} = $results[$i]->{'kohafield'};
+                       $row_data{label} = $results[$i]->{'label'};
+                       $row_data{sorts} = $results[$i]->{'sorts'};
+                       $row_data{attr} = $results[$i]->{'attr'};
+                       $row_data{recordtype} = $results[$i]->{'recordtype'};
+                       $row_data{tagfield} = $results[$i]->{'tagfield'};
+                       $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
+                       $row_data{opacshow} = $results[$i]->{'opacshow'};
+                       $row_data{intrashow} = $results[$i]->{'intrashow'};
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{toggle} = $toggle;
+                       push(@loop_data, \%row_data);
+                       $i++;
+               }
+               $template->param(select_display => "True",
+                                               loop => address@hidden);
+               $sth->finish;
+       } else {
+               #here, normal old style : display every tags
+               my ($count,@results)=StringSearch($dbh,$searchfield);
+               $cnt = $count;
+               my $toggle=0;
+               my @loop_data = ();
+               for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+                       if ($toggle eq 0){
+                               $toggle=1;
+                       } else {
+                               $toggle=0;
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{id} = $results[$i]->{'id'};
+                       $row_data{kohafield} = $results[$i]->{'kohafield'};
+                       $row_data{label} = $results[$i]->{'label'};
+                       $row_data{sorts} = $results[$i]->{'sorts'};
+                       $row_data{attr} = $results[$i]->{'attr'};
+                       $row_data{recordtype} = $results[$i]->{'recordtype'};
+                       $row_data{tagfield} = $results[$i]->{'tagfield'};
+                       $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
+                       $row_data{opacshow} = $results[$i]->{'opacshow'};
+                       $row_data{intrashow} = $results[$i]->{'intrashow'};
+                       $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{toggle} = $toggle;
+                       push(@loop_data, \%row_data);
+               }
+               $template->param(loop => address@hidden);
+       }
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param(isprevpage => $offset,
+                                               prevpage=> $prevpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               
+               );
+       }
+       if ($offset+$pagesize<$cnt) {
+               my $nextpage =$offset+$pagesize;
+               $template->param(nextpage =>$nextpage,
+                                               searchfield => $searchfield,
+                                               script_name => $script_name,
+                                               
+               );
+       }
+} #---- END $OP eq DEFAULT
+
+$template->param(loggeninuser => $loggedinuser,
+               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+#
+# the sub used for searches
+#
+sub StringSearch  {
+       my ($dbh,$searchstring)address@hidden;
+       my $sth=$dbh->prepare("Select * from koha_attr  where kohafield >=?  
order by kohafield");
+       $sth->execute($searchstring);
+       my @dataresults;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@dataresults,$data);
+
+       }
+
+       $sth->finish;
+       return (scalar(@dataresults),@dataresults);
+}
+
+
+

Index: onlinedatabases.pl
===================================================================
RCS file: onlinedatabases.pl
diff -N onlinedatabases.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ onlinedatabases.pl  25 Mar 2007 23:14:17 -0000      1.1.2.1
@@ -0,0 +1,225 @@
+#!/usr/bin/perl
+
+#script to administer the branches table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+use strict;
+use CGI;
+use C4::Search;
+use C4::Context;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from online_databases where (server 
like ?) ");
+       $sth->execute("$data[0]\%");
+       my @results;
+       while (my $data=$sth->fetchrow_hashref) {
+           push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       $dbh->disconnect;
+       return (scalar(@results),address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('searchfield');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/onlinedatabases.pl";
+
+my $pagesize=20;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+
+my ($template, $loggedinuser, $cookie) 
+    = get_template_and_user({template_name => "admin/onlinedatabases.tmpl",
+                               query => $input,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {parameters => 1},
+                               debug => 1,
+                               });
+
+
+$template->param(script_name => $script_name,
+                 searchfield => $searchfield);
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select * from online_databases where 
server = ? ");
+               $sth->execute($searchfield);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       
+       $template->param(host => $data->{'host'},
+                        port => $data->{'port'},
+                        db   => $data->{'db'},
+                        userid => $data->{'userid'},
+                        password => $data->{'password'},
+                       server => $data->{'server'},
+                        search_string => $data->{'search_string'},
+                       any => $data->{'any'},
+                        title => $data->{'title'},
+                       author => $data->{'author'},
+                        subject => $data->{'subject'},
+                       any_query => $data->{'any_query'},
+                        title_query => $data->{'title_query'},
+                       author_query => $data->{'author_query'},
+                        subject_query => $data->{'subject_query'},
+                       );
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $template->param(add_validate => 1);
+       my $dbh=C4::Context->dbh;
+       my $sth=$dbh->prepare("select * from online_databases where server=?");
+       $sth->execute($input->param('searchfield'));
+       if ($sth->rows) {
+               $sth=$dbh->prepare("update online_databases set host=?, port=?, 
db=?, userid=?, password=?, server=?, 
search_string=?,any=?,title=?,author=?,subject=?,any_query=?,title_query=?,author_query=?,subject_query=?
 where server=?");
+               $sth->execute($input->param('host'),
+                     $input->param('port'),
+                     $input->param('db'),
+                     $input->param('userid'),
+                     $input->param('password'),
+                     $input->param('searchfield'),
+                     $input->param('search_string'),
+                  $input->param('any'),
+                        $input->param('title'),
+               $input->param('author'),
+               $input->param('subject'),
+                $input->param('any_query'),
+                        $input->param('title_query'),
+               $input->param('author_query'),
+               $input->param('subject_query'),
+                     $input->param('searchfield'),
+                     );
+       } else {
+               $sth=$dbh->prepare("insert into online_databases 
(host,port,db,userid,password,server,search_string,any,title,author,subject,any_query,title_query,author_query,subject_query)
 values (?,?,?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
+               $sth->execute($input->param('host'),
+                     $input->param('port'),
+                     $input->param('db'),
+                     $input->param('userid'),
+                     $input->param('password'),
+                     $input->param('searchfield'),
+                     $input->param('search_string'),
+                     $input->param('fulltext_field'),
+                  $input->param('any'),
+                        $input->param('title'),
+               $input->param('author'),
+               $input->param('subject'),
+                $input->param('any_query'),
+                        $input->param('title_query'),
+               $input->param('author_query'),
+               $input->param('subject_query'),
+                     );
+       }
+       $sth->finish;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $template->param(delete_confirm => 1);
+       my $dbh = C4::Context->dbh;
+
+       my $sth2=$dbh->prepare("select * from online_databases where (server = 
?) ");
+       $sth2->execute($searchfield);
+       my $data=$sth2->fetchrow_hashref;
+       $sth2->finish;
+
+        $template->param(host => $data->{'host'},
+                        port => $data->{'port'},
+                        db   => $data->{'db'},
+                        userid => $data->{'userid'},
+                        password => $data->{'password'},
+                       server => $data->{'server'},
+                        search_string => $data->{'search_string'},
+                       any => $data->{'any'},
+                        title => $data->{'title'},
+                       author => $data->{'author'},
+                        subject => $data->{'subject'},
+                       );
+
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       $template->param(delete_confirmed => 1);
+       my $dbh=C4::Context->dbh;
+       my $sth=$dbh->prepare("delete from online_databases where server=?");
+       $sth->execute($searchfield);
+       $sth->finish;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       $template->param(else => 1);
+
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my @loop;
+       my $toggle = 0;
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+                       
+               my $urlsearchfield=$results->[$i]{name};
+               $urlsearchfield=~s/ /%20/g;
+               my %row = ( server => $results->[$i]{'server'},
+                       host => $results->[$i]{'host'},
+                       port => $results->[$i]{'port'},
+                       db => $results->[$i]{'db'},
+                       userid =>$results->[$i]{'userid'},
+                       
+                       toggle => $toggle);
+               push @loop, \%row;
+
+                if ( $toggle eq 0 )
+                {
+                        $toggle = 1;
+                }
+                else
+                {
+                        $toggle = 0;
+                }
+
+       }
+       $template->param(loop => address@hidden);
+       if ($offset>0) {
+               $template->param(offsetgtzero => 1,
+                               prevpage => $offset-$pagesize);
+       }
+       if ($offset+$pagesize<$count) {
+               $template->param(ltcount => 1,
+                                nextpage => $offset+$pagesize);
+       }
+} #---- END $OP eq DEFAULT
+
+output_html_with_http_headers $input, $cookie, $template->output;

Index: printers.pl
===================================================================
RCS file: printers.pl
diff -N printers.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ printers.pl 25 Mar 2007 23:14:17 -0000      1.14.2.2
@@ -0,0 +1,185 @@
+#!/usr/bin/perl
+
+#script to administer the aqbudget table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+
+# 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::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $query="";
+       my $sth=$dbh->prepare("Select printername,printqueue,printtype from 
printers where (printername like ?) order by printername");
+       $sth->execute("$data[0]%");
+       my @results;
+       my $cnt=0;
+       while (my $data=$sth->fetchrow_hashref){
+       push(@results,$data);
+       $cnt ++;
+       }
+       #  $sth->execute;
+       $sth->finish;
+       return ($cnt,address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('searchfield');
+my $pkfield="";
+my $reqsel="";
+my $reqdel="";
+#my $branchcode=$input->param('branchcode');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/printers.pl";
+
+my $pagesize=20;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "admin/printers.tmpl",
+                             query => $input,
+                             type => "intranet",
+                             authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                             debug => 1,
+                             });
+
+
+$template->param(searchfield => $searchfield,
+                script_name => $script_name);
+
+#start the page and read in includes
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select printername,printqueue,printtype 
from printers where printername=?");
+               $sth->execute($searchfield);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+
+       $template->param(printqueue => $data->{'printqueue'},
+                        printtype => $data->{'printtype'});
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $template->param(add_validate => 1);
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("replace printers 
(printername,printqueue,printtype) values (?,?,?)");
+       
$sth->execute($input->param('printername'),$input->param('printqueue'),$input->param('printtype'));
+       $sth->finish;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $template->param(delete_confirm => 1);
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select printername,printqueue,printtype from 
printers where printername=?");
+       $sth->execute($searchfield);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(printqueue => $data->{'printqueue'},
+                        printtype  => $data->{'printtype'});
+       
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       $template->param(delete_confirmed => 1);
+
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("delete from printers where printername=?");
+       $sth->execute($searchfield);
+       $sth->finish;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       $template->param(else => 1);
+
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my $toggle="white";
+       my @loop;
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               my %row = ( printername => $results->[$i]{'printername'},
+                           printqueue  => $results->[$i]{'printqueue'},
+                           printtype   => $results->[$i]{'printtype'},
+                           toggle      => $toggle);
+               push @loop, \%row;
+
+                if ( $toggle eq 'white' )
+                {
+                        $toggle = '#ffffcc';
+                }
+                else
+                {
+                        $toggle = 'white';
+                }
+       }
+       
+       $template->param(loop => address@hidden);
+       
+       if ($offset>0) {
+               $template->param(offsetgtzero => 1,
+                                prevpage => $offset-$pagesize);
+       }
+       print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
+       if ($offset+$pagesize<$count) {
+               $template->param(ltcount => 1,
+                                nextpage => $offset+$pagesize);
+       }
+
+} #---- END $OP eq DEFAULT
+
+output_html_with_http_headers $input, $cookie, $template->output;
+

Index: systempreferences.pl
===================================================================
RCS file: systempreferences.pl
diff -N systempreferences.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ systempreferences.pl        25 Mar 2007 23:14:17 -0000      1.36.2.2
@@ -0,0 +1,424 @@
+#!/usr/bin/perl
+
+#script to administer the systempref table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+
+# 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::Auth;
+use C4::Context;
+use C4::Koha;
+use C4::Output;
+use C4::Interface::CGI::Output;
+use C4::Search;
+use C4::Context;
+
+my %tabsysprefs;
+# Acquisitions
+       $tabsysprefs{acquisitions}="Acquisitions";
+       $tabsysprefs{gist}="Acquisitions";
+# Admin
+       $tabsysprefs{dateformat}="Admin";
+       $tabsysprefs{insecure}="Admin";
+       $tabsysprefs{KohaAdmin}="Admin";
+# Authorities
+       $tabsysprefs{authoritysep}="Authorities";
+# Catalogue
+       $tabsysprefs{advancedMARCEditor}="Catalogue";
+       $tabsysprefs{autoBarcode}="Catalogue";
+       $tabsysprefs{hide_marc}="Catalogue";
+       $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
+       $tabsysprefs{ISBD}="Catalogue";
+       $tabsysprefs{itemcallnumber}="Catalogue";
+       $tabsysprefs{LabelMARCView}="Catalogue";
+       $tabsysprefs{marc}="Catalogue";
+       $tabsysprefs{marcflavour}="Catalogue";
+       $tabsysprefs{serialsadditems}="Catalogue";
+       $tabsysprefs{sortbynonfiling}="Catalogue";
+       $tabsysprefs{MARCOrgCode}="Catalogue";
+       $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
+       $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
+       $tabsysprefs{SQLorZEBRA}="Catalogue";
+       
+# Circulation
+       $tabsysprefs{maxoutstanding}="Circulation";
+       $tabsysprefs{maxreserves}="Circulation";
+       $tabsysprefs{noissuescharge}="Circulation";
+       $tabsysprefs{patronimages}="Circulation";
+       $tabsysprefs{printcirculationslips}="Circulation";
+       $tabsysprefs{ReturnBeforeExpiry}="Circulation";
+       $tabsysprefs{allowrenewalsbefore}="Circulation";
+       $tabsysprefs{defaultBranch}="Circulation";
+       $tabsysprefs{strictrenewals}="Circulation";
+# Intranet
+       $tabsysprefs{TemplateEncoding}="Intranet";
+       $tabsysprefs{template}="Intranet";
+       $tabsysprefs{intranetstylesheet}="Intranet";
+       $tabsysprefs{IntranetNav}="Intranet";
+       $tabsysprefs{intranetcolorstylesheet}="Intranet";
+       $tabsysprefs{Activate_Log}="Intranet";
+       $tabsysprefs{allowrenewalsbefore}="Intranet";
+       
+       $tabsysprefs{zebrawait}="Intranet";
+       $tabsysprefs{retrieve_from}="Intranet";
+       $tabsysprefs{batchMode}="Intranet";
+       
+# Members
+       $tabsysprefs{automembernum}="Members";
+       $tabsysprefs{checkdigit}="Members";
+       $tabsysprefs{NotifyBorrowerDeparture}="Members";
+# OPAC
+       $tabsysprefs{AmazonAssocTag}="OPAC";
+       $tabsysprefs{AmazonContent}="OPAC";
+       $tabsysprefs{AmazonDevKey}="OPAC";
+       $tabsysprefs{AnonSuggestions}="OPAC";
+       $tabsysprefs{BiblioDefaultView}="OPAC";
+       $tabsysprefs{Disable_Dictionary}="OPAC";
+       $tabsysprefs{hidelostitems}="OPAC";
+       $tabsysprefs{LibraryName}="OPAC";
+       $tabsysprefs{opacbookbag}="OPAC";
+       $tabsysprefs{opaccolorstylesheet}="OPAC";
+       $tabsysprefs{opaccredits}="OPAC";
+       $tabsysprefs{opaclanguages}="OPAC";
+       $tabsysprefs{opaclanguagesdisplay}="OPAC";
+       $tabsysprefs{opaclargeimage}="OPAC";
+       $tabsysprefs{opaclayoutstylesheet}="OPAC";
+       $tabsysprefs{OpacNav}="OPAC";
+       $tabsysprefs{OpacPasswordChange}="OPAC";
+       $tabsysprefs{opacreadinghistory}="OPAC";
+       $tabsysprefs{opacsmallimage}="OPAC";
+       $tabsysprefs{opacstylesheet}="OPAC";
+       $tabsysprefs{opacthemes}="OPAC";
+       $tabsysprefs{opacuserlogin}="OPAC";
+       $tabsysprefs{SubscriptionHistory}="OPAC";
+       $tabsysprefs{suggestion}="OPAC";
+       $tabsysprefs{virtualshelves}="OPAC";
+       $tabsysprefs{opacheader}="OPAC";
+       $tabsysprefs{allowrenewsfromopac}="OPAC";
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my @results;
+       my $cnt=0;
+       if ($type){
+               foreach my $syspref (sort keys %tabsysprefs){
+                       if ($tabsysprefs{$syspref} eq $type){
+                               my $sth=$dbh->prepare("Select 
variable,value,explanation,type,options from systempreferences where (variable 
like ?) order by variable");
+                               $sth->execute($syspref);
+                               while (my $data=$sth->fetchrow_hashref){
+                                       $data->{value} =~ s/</&lt;/g;
+                                       $data->{value} =~ s/>/&lt;/g;
+                                       
$data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) 
>100;
+                                       push(@results,$data);
+                                       $cnt++;
+                               }
+                               $sth->finish;
+                       }
+               }
+       } else {
+               my $strsth ="Select variable,value,explanation,type,options 
from systempreferences where variable not in (";  
+               foreach my $syspref (keys %tabsysprefs){
+                       $strsth .= $dbh->quote($syspref).",";
+               }
+               $strsth =~ s/,$/) /;
+               $strsth .= " order by variable";
+               #warn $strsth;
+               my $sth=$dbh->prepare($strsth);
+               $sth->execute();
+               while (my $data=$sth->fetchrow_hashref){
+                       $data->{value}=substr($data->{value},0,100);
+                       push(@results,$data);
+                       $cnt++;
+               }
+               $sth->finish;
+       }
+       return ($cnt,address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('searchfield');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/systempreferences.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+my $pagesize=100;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+
+if ($op eq 'update_and_reedit') {
+       foreach ($input->param) {
+       }
+       my $value='';
+       if (my $currentorder=$input->param('currentorder')) {
+               my @currentorder=split /\|/, $currentorder;
+               my $orderchanged=0;
+               foreach my $param ($input->param) {
+                       if ($param=~m#up-(\d+).x#) {
+                               my $temp=$currentorder[$1];
+                               $currentorder[$1]=$currentorder[$1-1];
+                               $currentorder[$1-1]=$temp;
+                               $orderchanged=1;
+                               last;
+                       } elsif ($param=~m#down-(\d+).x#) {
+                               my $temp=$currentorder[$1];
+                               $currentorder[$1]=$currentorder[$1+1];
+                               $currentorder[$1+1]=$temp;
+                               $orderchanged=1;
+                               last;
+                       }
+               }
+               $value=join ' ', @currentorder;
+               if ($orderchanged) {
+                       $op='add_form';
+                       $template->param(script_name => $script_name,
+                                                       $op              => 1); 
# we show only the TMPL_VAR names $op
+               } else {
+                       $op='';
+                       $searchfield='';
+                       $template->param(script_name => $script_name,
+                                                       else              => 
1); # we show only the TMPL_VAR names $op
+               }
+       }
+       my $dbh = C4::Context->dbh;
+       my $query="select * from systempreferences where variable=?";
+       my $sth=$dbh->prepare($query);
+       $sth->execute($input->param('variable'));
+       if ($sth->rows) {
+               unless (C4::Context->config('demo') eq 1) {
+                       my $sth=$dbh->prepare("update systempreferences set 
value=?,explanation=?,type=?,options=? where variable=?");
+                       $sth->execute($value, $input->param('explanation'), 
$input->param('variable'), $input->param('preftype'), 
$input->param('prefoptions'));
+                       $sth->finish;
+               }
+    } else {
+               unless (C4::Context->config('demo') eq 1) {
+                       my $sth=$dbh->prepare("insert into systempreferences 
(variable,value,explanation) values (?,?,?,?,?)");
+                       $sth->execute($input->param('variable'), 
$input->param('value'), $input->param('explanation'), 
$input->param('preftype'), $input->param('prefoptions'));
+                       $sth->finish;
+               }
+       }
+       $sth->finish;
+
+}
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+
+if ($op eq 'add_form') {
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select 
variable,value,explanation,type,options from systempreferences where 
variable=?");
+               $sth->execute($searchfield);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+               $template->param(modify => 1);
+       }
+
+       my @options;
+       foreach my $option (split(/\|/, $data->{'options'})) {
+               my $selected='0';
+               $option eq $data->{'value'} and $selected=1;
+               push @options, { option => $option, selected => $selected };
+       }
+       if ($data->{'type'} eq 'Choice') {
+               $template->param('type-choice' => 1);
+       } elsif ($data->{'type'} eq 'YesNo') {
+               $template->param('type-yesno' => 1);
+               
$data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
+               ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) 
: ($template->param('value-no'=>1));
+       } elsif ($data->{'type'} eq 'Integer') {
+               $template->param('type-free' => 1);
+               $template->param('fieldlength' => $data->{'options'});
+       } elsif ($data->{'type'} eq 'Textarea') {
+               $template->param('type-textarea' => 1);
+               $data->{options} =~ /(.*)\|(.*)/;
+               $template->param('cols' => $1, 'rows' => $2);;
+       } elsif ($data->{'type'} eq 'Float') {
+               $template->param('type-free' => 1);
+               $template->param('fieldlength' => $data->{'options'});
+       } elsif ($data->{'type'} eq 'Themes') {
+               $template->param('type-choice' => 1);
+               my $type='';
+               ($data->{'variable'}=~m#opac#i) ? ($type='opac') : 
($type='intranet');
+               @options=();
+               my $currently_selected_themes;
+               my $counter=0;
+               foreach my $theme (split /\s+/, $data->{'value'}) {
+                   push @options, { option => $theme, counter => $counter };
+                   $currently_selected_themes->{$theme}=1;
+                   $counter++;
+               }
+               foreach my $theme (getallthemes($type)) {
+                       my $selected='0';
+                       next if $currently_selected_themes->{$theme};
+                       push @options, { option => $theme, counter => $counter 
};
+                       $counter++;
+               }
+       } elsif ($data->{'type'} eq 'Languages') {
+               $template->param('type-choice' => 1);
+               my $type='';
+               @options=();
+               my $currently_selected_languages;
+               my $counter=0;
+               foreach my $language (split /\s+/, $data->{'value'}) {
+                   next if $language eq 'images';
+                   push @options, { option => $language, counter => $counter };
+                   $currently_selected_languages->{$language}=1;
+                   $counter++;
+               }
+               foreach my $language (getalllanguages()) {
+                       next if $language eq 'images';
+                       my $selected='0';
+                       next if $currently_selected_languages->{$language};
+                       push @options, { option => $language, counter => 
$counter };
+                       $counter++;
+               }
+       } else {
+               $template->param('type-free' => 1);
+               $template->param('fieldlength' => 
$data->{'options'}>0?$data->{'options'}:60);
+       }
+       $template->param(explanation => $data->{'explanation'},
+                        value => $data->{'value'},
+                        type => $data->{'type'},
+                        options => address@hidden,
+                        preftype => $data->{'type'},
+                        prefoptions => $data->{'options'},
+                        searchfield => $searchfield);
+
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select * from systempreferences where 
variable=?");
+       $sth->execute($input->param('variable'));
+       if ($sth->rows) {
+               unless (C4::Context->config('demo') eq 1) {
+                       my $sth=$dbh->prepare("update systempreferences set 
value=?,explanation=?,type=?,options=? where variable=?");
+                       $sth->execute($input->param('value'), 
$input->param('explanation'), $input->param('preftype'), 
$input->param('prefoptions'), $input->param('variable'));
+                       $sth->finish;
+               }
+       } else {
+               unless (C4::Context->config('demo') eq 1) {
+                       my $sth=$dbh->prepare("insert into systempreferences 
(variable,value,explanation,type,options) values (?,?,?,?,?)");
+                       $sth->execute($input->param('variable'), 
$input->param('value'), $input->param('explanation'), 
$input->param('preftype'), $input->param('prefoptions'));
+                       $sth->finish;
+               }
+       }
+       $sth->finish;
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
+       exit;
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select variable,value,explanation,type,options 
from systempreferences where variable=?");
+       $sth->execute($searchfield);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(searchfield => $searchfield,
+                                                       Tvalue => 
$data->{'value'},
+                                                       );
+
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("delete from systempreferences where variable=?");
+       $sth->execute($searchfield);
+       $sth->finish;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       #Adding tab management for system preferences
+       my $tab=$input->param('tab');
+       
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,$tab);
+       my $toggle=0;
+       my @loop_data = ();
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+               if ($toggle eq 0){
+                       $toggle=1;
+               } else {
+                       $toggle=0;
+               }
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{variable} = $results->[$i]{'variable'};
+               $row_data{value} = $results->[$i]{'value'};
+               $row_data{explanation} = $results->[$i]{'explanation'};
+               $row_data{toggle} = $toggle;
+               $row_data{edit} = 
"$script_name?op=add_form&amp;searchfield=".$results->[$i]{'variable'};
+               $row_data{delete} = 
"$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'variable'};
+               push(@loop_data, \%row_data);
+       }
+       $tab=($tab?$tab:"Others");
+       $template->param(loop => address@hidden, $tab => 1);
+       if ($offset>0) {
+               my $prevpage = $offset-$pagesize;
+               $template->param("<a 
href=$script_name?offset=".$prevpage.'&lt;&lt; Prev</a>');
+       }
+       if ($offset+$pagesize<$count) {
+               my $nextpage =$offset+$pagesize;
+               $template->param("a href=$script_name?offset=".$nextpage.'Next 
&gt;&gt;</a>');
+       }
+} #---- END $OP eq DEFAULT
+$template->param(intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
+output_html_with_http_headers $input, $cookie, $template->output;

Index: thesaurus.pl
===================================================================
RCS file: thesaurus.pl
diff -N thesaurus.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ thesaurus.pl        25 Mar 2007 23:14:17 -0000      1.14.2.2
@@ -0,0 +1,266 @@
+#!/usr/bin/perl
+
+# 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::Auth;
+use C4::Interface::CGI::Output;
+use C4::Context;
+use C4::Output;
+use C4::Search;
+use C4::Authorities;
+
+my $input = new CGI;
+my $search_category=$input->param('search_category');
+# $search_category=$input->param('category') unless $search_category;
+#my $toponly = $input->param('toponly');
+my $branch = $input->param('branch');
+my $searchstring = $input->param('searchstring');
+# $searchstring=~ s/\,//g;
+my $id = $input->param('id');
+my $offset=$input->param('offset');
+my $father=$input->param('father');
+
+my $reqsel="";
+my $reqdel="delete from bibliothesaurus where id='$id'";
+my $script_name="/cgi-bin/koha/admin/thesaurus.pl";
+my $dbh = C4::Context->dbh;
+my $authoritysep = C4::Context->preference("authoritysep");
+
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/thesaurus.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
+my $pagesize=20;
+
+my $prevpage = $offset-$pagesize;
+my $nextpage =$offset+$pagesize;
+
+my $op = $input->param('op');
+
+if ($op) {
+$template->param(script_name => $script_name,
+                                               $op              => 1); # we 
show only the TMPL_VAR names $op
+} else {
+$template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+}
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       my $data;
+       if ($id) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select id,category,freelib,stdlib from 
bibliothesaurus where id=?");
+               $sth->execute($id);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       } else {
+               $data->{'category'} = $input->param('category');
+               $data->{'stdlib'} = $input->param('stdlib');
+       }
+       if ($search_category) {
+               $template->param(action => "Modify thesaurus");
+       } else {
+               $template->param(action => "Add thesaurus");
+       }
+       $template->param(category => $data->{'category'},
+                                                       stdlib => 
$data->{'stdlib'},
+                                                       freelib => 
$data->{'freelib'},
+                                                       id => $data->{'id'},
+                                                       branch => $branch,
+#                                                      toponly => $toponly,
+                                                       search_category => 
$search_category,
+                                                       searchstring => 
$searchstring,
+                                                       offset => $offset,
+                                                       father => $father,
+                                                       );
+       if ($data->{'category'}) {
+               $template->param(category => "<input type=\"hidden\" 
name=\"category\" value='$data->{'category'}'>$data->{'category'}");
+       } else {
+               $template->param(category => "<input type=text 
name=\"category\" size=8 maxlength=8>");
+       }
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert data in DB
+} elsif ($op eq 'add_validate') {
+       my $dbh = C4::Context->dbh;
+       my $freelib = $input->param('freelib');
+       $freelib = $input->param('stdlib') unless ($input->param('freelib'));
+       newauthority($dbh,$input->param('category'),$input->param('father')." 
".$input->param('stdlib'), $freelib,'',1,'');
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=thesaurus.pl?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset\"></html>";
+       exit;
+################## MOD_VALIDATE ##################################
+# called by add_form, used to modify data in DB
+} elsif ($op eq 'mod_validate') {
+       my $dbh = C4::Context->dbh;
+       my $freelib = $input->param('freelib');
+       modauthority($dbh,$id,$freelib);
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=thesaurus.pl?branch=$branch&search_category=$search_category&offset=$offset&searchstring=".CGI::escapeHTML($searchstring)."\"></html>";
+       exit;
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       my $dbh = C4::Context->dbh;
+       my $sth=$dbh->prepare("select category,stdlib,freelib from 
bibliothesaurus where id=?");
+       $sth->execute($id);
+       my $data=$sth->fetchrow_hashref;
+       $sth->finish;
+       $template->param(search_category => $search_category,
+                                                       Tvalue => 
$data->{'stdlib'},
+                                                       id =>$id,
+                                                       );
+
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       &delauthority($id);
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; 
URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
+       exit;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DETAIL_FORM ##################################
+} elsif ($op eq 'detail_form') {
+       # build categories list
+       my $sth = $dbh->prepare("select distinct category from 
bibliothesaurus");
+       $sth->execute;
+       my @category_list;
+       while ( my ($category) = $sth->fetchrow_array) {
+               push(@category_list,$category);
+       }
+       my $tab_list = CGI::scrolling_list(-name=>'search_category',
+                       -values=> address@hidden,
+                       -default=>"$search_category",
+                       -size=>1,
+                       -multiple=>0,
+                       );
+       if (!$search_category) {
+               $search_category=$category_list[0];
+       }
+       my $env;
+       my $sth = $dbh->prepare("select father,stdlib,category,hierarchy from 
bibliothesaurus where id=?");
+       $sth->execute($id);
+       my ($father,$stdlib,$category,$suphierarchy) = $sth->fetchrow_array;
+       $sth->finish;
+       $sth= $dbh->prepare("select id,freelib from bibliothesaurus where 
father=? and stdlib=?");
+       $sth->execute($father,$stdlib);
+       my $toggle="white";
+       # builds value list
+       my @loop_data;
+       while ( my ($id,$freelib) = $sth->fetchrow_array) {
+               if ($toggle eq 'white'){
+                       $toggle="#ffffcc";
+               } else {
+                       $toggle="white";
+               }
+               my %row_data;  # get a fresh hash for the row data
+               $row_data{freelib} = $freelib;
+               $row_data{edit} = "$script_name?op=add_form&id=$id";
+               $row_data{delete} = 
"$script_name?op=delete_confirm&search_category=$search_category&id=$id";
+               push(@loop_data, \%row_data);
+       }
+
+       $template->param(loop => address@hidden,
+                                                       tab_list => $tab_list,
+                                                       category => 
$search_category,
+#                                                      toponly => $toponly,
+                                                       searchstring => 
$searchstring,
+                                                       stdlib => $stdlib,
+                                                       category => $category);
+################## DEFAULT ##################################
+} else { # DEFAULT
+       # build categories list
+       my $sth = $dbh->prepare("select distinct category from 
bibliothesaurus");
+       $sth->execute;
+       my @category_list;
+       while ( my ($category) = $sth->fetchrow_array) {
+               push(@category_list,$category);
+       }
+       my $tab_list = CGI::scrolling_list(-name=>'search_category',
+                       -values=> address@hidden,
+                       -default=>"$search_category",
+                       -size=>1,
+                       -multiple=>0,
+                       );
+       if (!$search_category) {
+               $search_category=$category_list[0];
+       }
+       my $env;
+       my 
($count,$results)=searchauthority($env,$search_category,$branch,$searchstring,$offset,$pagesize);
+       my $toggle="white";
+       my @loop_data = ();
+       # builds value list
+       for (my $i=0; $i < $pagesize; $i++){
+               if ($results->[$i]{'stdlib'}) {
+                       if ($toggle eq 'white'){
+                               $toggle="#ffffcc";
+                       } else {
+                               $toggle="white";
+                       }
+                       my %row_data;  # get a fresh hash for the row data
+                       $row_data{category} = $results->[$i]{'category'};
+#                      $row_data{stdlib} = ("&nbsp;&nbsp;&nbsp;&nbsp;" x 
$results->[$i]{'level'}).$results->[$i]{'stdlib'};
+                       $row_data{stdlib} = $results->[$i]{'stdlib'};
+                       $row_data{freelib} = $results->[$i]{'freelib'};
+                       $row_data{freelib} =~ s/($searchstring)/<b>$1<\/b>/gi;
+                       $row_data{father} = $results->[$i]{'father'};
+                       $row_data{dig} ="<a 
href=thesaurus.pl?branch=$results->[$i]{'hierarchy'}$results->[$i]{'id'}|&search_category=$search_category>";
+                       $row_data{related} ="<a 
href=thesaurus.pl?id=$results->[$i]{'id'}&search_category=$search_category&op=detail_form>";
+                       $row_data{edit} = 
"$script_name?op=add_form&branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset&id=".$results->[$i]{'id'};
+                       $row_data{delete} = 
"$script_name?op=delete_confirm&search_category=$search_category&id=".$results->[$i]{'id'};
+                       push(@loop_data, \%row_data);
+               }
+       }
+       # rebuild complete hierarchy
+       my  $sth = $dbh->prepare("select stdlib from bibliothesaurus where 
id=?");
+       my @hierarchy = split(/\|/,$branch);
+       my @hierarchy_loop;
+       my $x;
+       my $father;
+       for (my $xi=0;$xi<=$#hierarchy;$xi++) {
+               my %link;
+               $sth->execute($hierarchy[$xi]);
+               my ($t) = $sth->fetchrow_array;
+               $x.=$hierarchy[$xi]."|";
+               $link{'string'}=$t;
+               $link{'branch'}=$x;
+               push (@hierarchy_loop, \%link);
+               $father .= $t." $authoritysep ";
+       }
+       $template->param(loop => address@hidden,
+                                                       tab_list => $tab_list,
+                                                       category => 
$search_category,
+#                                                      toponly => $toponly,
+                                                       searchstring => 
$searchstring,
+                                                       hierarchy_loop => 
address@hidden,
+                                                       branch => $branch,
+                                                       father => $father);
+       if ($offset>0) {
+               $template->param(previous => 
"$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage");
+       }
+       if ($pagesize<$count) {
+               $template->param(next => 
"$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage");
+       }
+} #---- END $OP eq DEFAULT
+
+output_html_with_http_headers $input, $cookie, $template->output;

Index: viewlog.pl
===================================================================
RCS file: viewlog.pl
diff -N viewlog.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ viewlog.pl  25 Mar 2007 23:14:17 -0000      1.4.2.2
@@ -0,0 +1,148 @@
+#!/usr/bin/perl
+
+# $Id: viewlog.pl,v 1.4.2.2 2007/03/25 23:14:17 tgarip1957 Exp $
+
+# 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 C4::Auth;
+use CGI;
+use C4::Context;
+use C4::Koha;
+use C4::Interface::CGI::Output;
+use C4::Log;
+use C4::Date;
+
+=head1 NAME
+
+plugin that shows a stats on catalogers
+
+=head1 DESCRIPTION
+
+
+=over2
+
+=cut
+
+my $input = new CGI;
+my $do_it=$input->param('do_it');
+my $fullreportname = "admin/viewlog.tmpl";
+my $modulename = $input->param("module");
+my $userfilter = $input->param("user");
+my $actionfilter = $input->param("action");
+my $fromfilter = $input->param("from");
+my $tofilter = $input->param("to");
+my $basename = $input->param("basename");
+my $mime = $input->param("MIME");
+my $del = $input->param("sep");
+my $output = $input->param("output");
+
+
+my ($template, $borrowernumber, $cookie)
+       = get_template_and_user({template_name => $fullreportname,
+                               query => $input,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {editcatalogue => 1},
+                               debug => 1,
+                               });
+$template->param(do_it => $do_it);
+if ($do_it) {
+# Displaying results
+       #building filters
+       my @filters;
+       push @filters, {name=> 'user', value=> $userfilter} if ($userfilter);
+       push @filters, {name=> 'action', value=> $actionfilter} if 
($actionfilter);
+       push @filters, {name=> 'from', value=> $fromfilter} if ($fromfilter);
+       push @filters, {name=> 'to', value=> $tofilter} if ($tofilter);
+       if ($modulename eq "cataloguing"){
+               my $titlefilter = $input->param("title");
+               my $authorfilter = $input->param("author");
+               my $publisherfilter = $input->param("publisher");
+               my $callnumberfilter = $input->param("barcode");
+               
+               push @filters, {name=> 'title', value=> $titlefilter} if 
($titlefilter);
+               push @filters, {name=> 'author', value=> $authorfilter} if 
($authorfilter);
+               push @filters, {name=> 'publisher', value=> $publisherfilter} 
if ($publisherfilter);
+               push @filters, {name=> 'callnumber', value=> $callnumberfilter} 
if ($callnumberfilter);
+       }
+       
+       my ($count, $results) = displaylog( $modulename, @filters);
+       if ($output eq "screen"){
+# Printing results to screen
+               $template->param(modulename =>$modulename, $modulename => 1, 
looprow => $results,counter=>$count);
+               output_html_with_http_headers $input, $cookie, 
$template->output;
+               exit(1);
+       } else {
+# Printing to a csv file
+               print $input->header(-type => 'application/vnd.sun.xml.calc',
+                       -attachment=>"$basename.csv",
+                       -filename=>"$basename.csv" );
+               my $sep;
+               $sep =C4::Context->preference("delimiter");
+# header top-right
+# Other header
+# Table
+               foreach my $line ( @$results ) {
+                       if ($modulename eq "catalogue"){
+                               print $line->{timestamp}.$sep;
+                               print $line->{firstname}.$sep;
+                               print $line->{surname}.$sep;
+                               print $line->{action}.$sep;
+                               print $line->{info}.$sep;
+                               print $line->{title}.$sep;
+                               print $line->{author}.$sep;
+                       }
+                       print "\n";
+               }
+# footer
+               exit(1);
+       }
+} else {
+       my $dbh = C4::Context->dbh;
+       my @values;
+       my %labels;
+       my %select;
+       my $req;
+       
+       my @mime = ( C4::Context->preference("MIME") );
+#      foreach my $mime (@mime){
+#              warn "".$mime;
+#      }
+       
+       my $CGIextChoice=CGI::scrolling_list(
+                               -name     => 'MIME',
+                               -id       => 'MIME',
+                               -values   => address@hidden,
+                               -size     => 1,
+                               -multiple => 0 );
+       
+       my @dels = ( C4::Context->preference("delimiter") );
+       my $CGIsepChoice=CGI::scrolling_list(
+                               -name     => 'sep',
+                               -id       => 'sep',
+                               -values   => address@hidden,
+                               -size     => 1,
+                               -multiple => 0 );
+       
+       $template->param(
+                                       CGIextChoice => $CGIextChoice,
+                                       CGIsepChoice => $CGIsepChoice
+                                       );
+output_html_with_http_headers $input, $cookie, $template->output;
+}

Index: z3950servers.pl
===================================================================
RCS file: z3950servers.pl
diff -N z3950servers.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ z3950servers.pl     25 Mar 2007 23:14:17 -0000      1.14.2.2
@@ -0,0 +1,228 @@
+#!/usr/bin/perl
+
+#script to administer the branches table
+#written 20/02/2002 by address@hidden
+# This software is placed under the gnu General Public License, v2 
(http://www.gnu.org/licenses/gpl.html)
+
+# ALGO :
+# this script use an $op to know what to do.
+# if $op is empty or none of the above values,
+#      - the default screen is build (with all records, or filtered datas).
+#      - the   user can clic on add, modify or delete record.
+# if $op=add_form
+#      - if primkey exists, this is a modification,so we read the $primkey 
record
+#      - builds the add/modify form
+# if $op=add_validate
+#      - the user has just send datas, so we create/modify the record
+# if $op=delete_form
+#      - we show the record having primkey=$primkey and ask for deletion 
validation form
+# if $op=delete_confirm
+#      - we delete the record having primkey=$primkey
+
+use strict;
+use C4::Output;
+use CGI;
+use C4::Search;
+use C4::Context;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+
+sub StringSearch  {
+       my ($env,$searchstring,$type)address@hidden;
+       my $dbh = C4::Context->dbh;
+       $searchstring=~ s/\'/\\\'/g;
+       my @data=split(' ',$searchstring);
+       my address@hidden;
+       my $sth=$dbh->prepare("Select * from z3950servers where (name like ?) 
order by rank,name");
+       $sth->execute("$data[0]\%");
+       my @results;
+       while (my $data=$sth->fetchrow_hashref) {
+           push(@results,$data);
+       }
+       #  $sth->execute;
+       $sth->finish;
+       $dbh->disconnect;
+       return (scalar(@results),address@hidden);
+}
+
+my $input = new CGI;
+my $searchfield=$input->param('searchfield');
+my $offset=$input->param('offset');
+my $script_name="/cgi-bin/koha/admin/z3950servers.pl";
+
+my $pagesize=20;
+my $op = $input->param('op');
+$searchfield=~ s/\,//g;
+
+my ($template, $loggedinuser, $cookie) 
+    = get_template_and_user({template_name => "admin/z3950servers.tmpl",
+                               query => $input,
+                               type => "intranet",
+                               authnotrequired => 0,
+                               flagsrequired => {parameters => 1},
+                               debug => 1,
+                               });
+
+
+$template->param(script_name => $script_name,
+                 searchfield => $searchfield);
+
+
+################## ADD_FORM ##################################
+# called by default. Used to create form to add or  modify a record
+if ($op eq 'add_form') {
+       $template->param(add_form => 1);
+       #---- if primkey exists, it's a modify action, so read values to 
modify...
+       my $data;
+       if ($searchfield) {
+               my $dbh = C4::Context->dbh;
+               my $sth=$dbh->prepare("select * from z3950servers where (name = 
?) order by rank,name");
+               $sth->execute($searchfield);
+               $data=$sth->fetchrow_hashref;
+               $sth->finish;
+       }
+       
+       $template->param(host => $data->{'host'},
+                        port => $data->{'port'},
+                        db   => $data->{'db'},
+                        userid => $data->{'userid'},
+                        password => $data->{'password'},
+               
+                       opacshow => CGI::checkbox(-name=>'opacshow',
+                                               -checked=> 
$data->{'opacshow'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'opacshow'),
+                       onlinecatalog => CGI::checkbox(-name=>'onlinecatalog',
+                                               -checked=> 
$data->{'onlinecatalog'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'onlinecatalog'),
+                       checked => CGI::checkbox(-name=>'checked',
+                                               -checked=> 
$data->{'checked'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'checked'),
+                        rank => $data->{'rank'});
+                                                                               
                        # END $OP eq ADD_FORM
+################## ADD_VALIDATE ##################################
+# called by add_form, used to insert/modify data in DB
+} elsif ($op eq 'add_validate') {
+       $template->param(add_validate => 1);
+       my $dbh=C4::Context->dbh;
+       my $sth=$dbh->prepare("select * from z3950servers where name=?");
+       $sth->execute($input->param('searchfield'));
+       if ($sth->rows) {
+               $sth=$dbh->prepare("update z3950servers set host=?, port=?, 
db=?, userid=?, password=?, name=?, checked=?, 
rank=?,opacshow=?,syntax=?,onlinecatalog=? where name=?");
+               $sth->execute($input->param('host'),
+                     $input->param('port'),
+                     $input->param('db'),
+                     $input->param('userid'),
+                     $input->param('password'),
+                     $input->param('searchfield'),
+                     $input->param('checked')?1:0,
+                     $input->param('rank'),
+                  $input->param('opacshow')?1:0,
+                        $input->param('syntax'),
+               $input->param('onlinecatalog')?1:0,
+                     $input->param('searchfield'),
+                     );
+       } else {
+               $sth=$dbh->prepare("insert into z3950servers 
(host,port,db,userid,password,name,checked,rank,opacshow,onlinecatalog,syntax) 
values (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
+               $sth->execute($input->param('host'), $input->param('port'), 
$input->param('db'), $input->param('userid'),
+                     $input->param('password'), 
$input->param('searchfield'),$input->param('checked')?1:0, 
$input->param('rank'),
+                     
$input->param('opacshow')?1:0,$input->param('onlinecatalog')?1:0,$input->param('syntax')
 );
+       }
+       $sth->finish;
+                                                                               
                        # END $OP eq ADD_VALIDATE
+################## DELETE_CONFIRM ##################################
+# called by default form, used to confirm deletion of data in DB
+} elsif ($op eq 'delete_confirm') {
+       $template->param(delete_confirm => 1);
+       my $dbh = C4::Context->dbh;
+
+       my $sth2=$dbh->prepare("select * from z3950servers where (name = ?) 
order by rank,name");
+       $sth2->execute($searchfield);
+       my $data=$sth2->fetchrow_hashref;
+       $sth2->finish;
+
+        $template->param(host => $data->{'host'},
+                         port => $data->{'port'},
+                         db   => $data->{'db'},
+                         userid => $data->{'userid'},
+                         password => $data->{'password'},
+                      checked => CGI::checkbox(-name=>'checked',
+                                               -checked=> 
$data->{'checked'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'checked'),
+               opacshow => CGI::checkbox(-name=>'opacshow',
+                                               -checked=> 
$data->{'opacshow'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'opacshow'),
+               onlinecatalog => CGI::checkbox(-name=>'onlinecatalog',
+                                               -checked=> 
$data->{'onlinecatalog'}?'checked':'',
+                                               -value=> 1,
+                                               -label => '',
+                                               -id=> 'onlinecatalog'),
+                         rank => $data->{'rank'});
+
+                                                                               
                        # END $OP eq DELETE_CONFIRM
+################## DELETE_CONFIRMED ##################################
+# called by delete_confirm, used to effectively confirm deletion of data in DB
+} elsif ($op eq 'delete_confirmed') {
+       $template->param(delete_confirmed => 1);
+       my $dbh=C4::Context->dbh;
+       my $sth=$dbh->prepare("delete from z3950servers where name=?");
+       $sth->execute($searchfield);
+       $sth->finish;
+                                                                               
                        # END $OP eq DELETE_CONFIRMED
+################## DEFAULT ##################################
+} else { # DEFAULT
+       $template->param(else => 1);
+
+       my $env;
+       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my @loop;
+       my $toggle = 0;
+       for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+                       
+               my $urlsearchfield=$results->[$i]{name};
+               $urlsearchfield=~s/ /%20/g;
+               my %row = ( name => $results->[$i]{'name'},
+                       host => $results->[$i]{'host'},
+                       port => $results->[$i]{'port'},
+                       db => $results->[$i]{'db'},
+                       userid =>$results->[$i]{'userid'},
+                       password => ($results->[$i]{'password'}) ? ('#######') 
: ('&nbsp;'),
+                       checked => $results->[$i]{'checked'},
+                       opacshow => $results->[$i]{'opacshow'},
+                       onlinecatalog => $results->[$i]{'onlinecatalog'},
+                       rank => $results->[$i]{'rank'},
+                       syntax => $results->[$i]{'syntax'},
+                       toggle => $toggle);
+               push @loop, \%row;
+
+                if ( $toggle eq 0 )
+                {
+                        $toggle = 1;
+                }
+                else
+                {
+                        $toggle = 0;
+                }
+
+       }
+       $template->param(loop => address@hidden);
+       if ($offset>0) {
+               $template->param(offsetgtzero => 1,
+                               prevpage => $offset-$pagesize);
+       }
+       if ($offset+$pagesize<$count) {
+               $template->param(ltcount => 1,
+                                nextpage => $offset+$pagesize);
+       }
+} #---- END $OP eq DEFAULT
+
+output_html_with_http_headers $input, $cookie, $template->output;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]