koha-devel
[Top][All Lists]
Advanced

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

[Koha-devel] CVS: koha/admin aqbookfund.pl,NONE,1.1 aqbudget.pl,NONE,1.1


From: Paul POULAIN
Subject: [Koha-devel] CVS: koha/admin aqbookfund.pl,NONE,1.1 aqbudget.pl,NONE,1.1 branches.pl,NONE,1.1 categorie.pl,NONE,1.1 categoryitem.pl,NONE,1.1 currency.pl,NONE,1.1 itemtypes.pl,NONE,1.1 printers.pl,NONE,1.1 stopwords.pl,NONE,1.1 systempreferences.pl,NONE,1.1
Date: Tue Mar 5 13:38:03 2002

Update of /cvsroot/koha/koha/admin
In directory usw-pr-cvs1:/tmp/cvs-serv20545/admin

Added Files:
        aqbookfund.pl aqbudget.pl branches.pl categorie.pl 
        categoryitem.pl currency.pl itemtypes.pl printers.pl 
        stopwords.pl systempreferences.pl 
Log Message:
scripts to manage parameters tables


--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select 
aqbudget.bookfundid,startdate,enddate,budgetamount,bookfundname from 
aqbudget,aqbookfund where aqbudget.bookfundid=aqbookfund.bookfundid and 
(aqbudget.bookfundid like \"$data[0]%\") order by bookfundid";
        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;
        $dbh->disconnect;
        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/aqbookfund.pl";
my $bookfundid=$input->param('bookfundid');
my $pagesize=20;
my $op = $input->param('op');
$searchfield=~ s/\,//g;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 ($bookfundid) {
                my $dbh = &C4Connect;
                my $sth=$dbh->prepare("select 
bookfundid,bookfundname,bookfundgroup from aqbookfund where 
bookfundid='$bookfundid'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.bookfundid.value.length==0) {
                        _alertString += "- bookfundid missing\\n";
                }
                if (f.bookfundname.value.length==0) {
                        _alertString += "- bookfundname missing\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($bookfundid) {
                print "<h1>Modify book fund</h1>";
        } else {
                print "<h1>Add book fund</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<input type=hidden name=checked value=0>";
        print "<table>";
        if ($bookfundid) {
                print "<tr><td>Book fund</td><td><input type=hidden 
name=bookfundid value=$bookfundid>$bookfundid</td></tr>";
        } else {
                print "<tr><td>Book fund</td><td><input type=text 
name=bookfundid size=5 maxlength=5 onBlur=toUC(this)></td></tr>";
        }
        print "<tr><td>Name</td><td><input type=text name=bookfundname size=40 
maxlength=80 value='$data->{'bookfundname'}'>&nbsp;</td></tr>";
        print "<tr><td>Group</td><td><input type=text name=bookfundgroup 
value='$data->{'bookfundgroup'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace aqbookfund (bookfundid,bookfundname,bookfundgroup) 
values (";
        $query.= $dbh->quote($input->param('bookfundid')).",";
        $query.= $dbh->quote($input->param('bookfundname')).",";
        $query.= $dbh->quote($input->param('bookfundgroup')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
#       my $sth=$dbh->prepare("select count(*) as total from categoryitem where 
itemtype='$itemtype'");
#       $sth->execute;
#       my $total = $sth->fetchrow_hashref;
#       $sth->finish;
        my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup 
from aqbookfund where bookfundid='$bookfundid'");
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print mktablerow(2,'#99cc33',bold('Book 
fund'),bold("$bookfundid"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=bookfundid 
value='$bookfundid'>";
        print "<tr><td>Name</td><td>$data->{'bookfundname'}</td></tr>";
        print "<tr><td>Group</td><td>$data->{'bookfundgroup'}</td></tr>";
#       if ($total->{'total'} >0) {
#               print "<tr><td colspan=2 align=center><b>This record is used 
$total->{'total'} times. Deletion not possible</b></td></tr>";
#               print "<tr><td colspan=2></form><form action='$script_name' 
method=post><input type=submit value=OK></form></td></tr>";
#       } else {
                print "<tr><td colspan=2 align=center>CONFIRM 
DELETION</td></tr>";
                print "<tr><td><INPUT type=submit 
value='YES'></form></td><td><form action='$script_name' method=post><input 
type=submit value=NO></form></td></tr>";
#       }
                                                                                
                        # 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=C4Connect;
        my $bookfundid=uc($input->param('bookfundid'));
        my $query = "delete from aqbookfund where bookfundid='$bookfundid'";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","searchfield",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'bookfund admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print mktablerow(6,'#99cc33',bold('Book fund'),bold('Start 
date'),bold('End date'),bold('Budget amount'),
        '&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                #find out stats
        #       my 
($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
        #       $fines=$fines+0;
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print mktablerow(6,$toggle,$results->[$i]{'bookfundid'},
                $results->[$i]{'bookfundname'},$results->[$i]{'bookfundgroup'},
                
mklink("$script_name?op=add_form&bookfundid=".$results->[$i]{'bookfundid'},'Edit'),
                
mklink("$script_name?op=delete_confirm&bookfundid=".$results->[$i]{'bookfundid'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add budget\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select 
aqbudget.bookfundid,startdate,enddate,budgetamount,bookfundname from 
aqbudget,aqbookfund where aqbudget.bookfundid=aqbookfund.bookfundid and 
(aqbudget.bookfundid like \"$data[0]%\") order by bookfundid";
        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;
        $dbh->disconnect;
        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/aqbudget.pl";
my $bookfundid=$input->param('bookfundid');
my $pagesize=20;
my $op = $input->param('op');
$searchfield=~ s/\,//g;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 ($bookfundid) {
                my $dbh = &C4Connect;
                my $sth=$dbh->prepare("select 
bookfundid,startdate,enddate,budgetamount,bookfundname from aqbudget,aqbookfund 
where aqbudget.bookfundid=aqbookfund.bookfundid and bookfundid='$bookfundid'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.bookfundid.value.length==0) {
                        _alertString += "- bookfundid missing\\n";
                }
                if (!(isNotNull(window.document.Aform.budgetamount,1))) {
                        _alertString += "- Budget missing\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($bookfundid) {
                print "<h1>Modify budget</h1>";
        } else {
                print "<h1>Add budget</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<input type=hidden name=checked value=0>";
        print "<table>";
        if ($bookfundid) {
                print "<tr><td>Book fund</td><td><input type=hidden 
name=bookfundid value=$bookfundid>$bookfundid</td></tr>";
        } else {
                print "<tr><td>Book fund</td><td><input type=text 
name=bookfundid size=5 maxlength=5 onBlur=toUC(this)></td></tr>";
        }
        print "<tr><td>Start date</td><td><input type=text name=startdate 
size=40 maxlength=80 value='$data->{'startdate'}'>&nbsp;</td></tr>";
        print "<tr><td>End date</td><td><input type=text name=enddate 
value='$data->{'enddate'}'></td></tr>";
        print "<tr><td>Budget amount</td><td><input type=text name=budgetamount 
value='$data->{'budgetamount'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace aqbudget 
(bookfundid,startdate,enddate,budgetamount) values (";
        $query.= $dbh->quote($input->param('bookfundid')).",";
        $query.= $dbh->quote($input->param('startdate')).",";
        $query.= $dbh->quote($input->param('enddate')).",";
        $query.= $dbh->quote($input->param('budgetamount')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
#       my $sth=$dbh->prepare("select count(*) as total from categoryitem where 
itemtype='$itemtype'");
#       $sth->execute;
#       my $total = $sth->fetchrow_hashref;
#       $sth->finish;
        my $sth=$dbh->prepare("select bookfundid,startdate,enddate,budgetamount 
from aqbudget where bookfundid='$bookfundid'");
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print mktablerow(2,'#99cc33',bold('Book 
fund'),bold("$bookfundid"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=bookfundid 
value='$bookfundid'>";
        print "<tr><td>Start date</td><td>$data->{'startdate'}</td></tr>";
        print "<tr><td>End date</td><td>$data->{'enddate'}</td></tr>";
        print "<tr><td>budgetamount</td><td>$data->{'budgetamount'}</td></tr>";
#       if ($total->{'total'} >0) {
#               print "<tr><td colspan=2 align=center><b>This record is used 
$total->{'total'} times. Deletion not possible</b></td></tr>";
#               print "<tr><td colspan=2></form><form action='$script_name' 
method=post><input type=submit value=OK></form></td></tr>";
#       } else {
                print "<tr><td colspan=2 align=center>CONFIRM 
DELETION</td></tr>";
                print "<tr><td><INPUT type=submit 
value='YES'></form></td><td><form action='$script_name' method=post><input 
type=submit value=NO></form></td></tr>";
#       }
                                                                                
                        # 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=C4Connect;
        my $bookfundid=uc($input->param('bookfundid'));
        my $query = "delete from aqbudget where bookfundid='$bookfundid'";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","searchfield",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'bookfund admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print mktablerow(6,'#99cc33',bold('Book fund'),bold('Start 
date'),bold('End date'),bold('Budget amount'),
        '&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                #find out stats
        #       my 
($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
        #       $fines=$fines+0;
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print mktablerow(6,$toggle,$results->[$i]{'bookfundid'}.' 
('.$results->[$i]{'bookfundname'}.')',
                $results->[$i]{'startdate'},$results->[$i]{'enddate'},
                $results->[$i]{'budgetamount'},
                
mklink("$script_name?op=add_form&bookfundid=".$results->[$i]{'bookfundid'},'Edit'),
                
mklink("$script_name?op=delete_confirm&bookfundid=".$results->[$i]{'bookfundid'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add budget\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select 
branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing
 from branches where (branchcode like \"$data[0]%\") order by branchcode";
        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;
        $dbh->disconnect;
        return ($cnt,address@hidden);
}

my $input = new CGI;
my $searchfield=$input->param('searchfield');
my $pkfield="branchcode";
my $reqsel="select 
branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing
 from branches where branchcode='$searchfield'";
my $reqdel="delete from branches where branchcode='$searchfield'";
#my $branchcode=$input->param('branchcode');
my $offset=$input->param('offset');
my $script_name="/cgi-bin/koha/admin/branches.pl";

my $pagesize=20;
my $op = $input->param('op');
$searchfield=~ s/\,//g;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 = &C4Connect;
                my $sth=$dbh->prepare("select 
branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing
  from branches where branchcode='$searchfield'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.searchfield.value.length==0) {
                        _alertString += "- branch code missing\\n";
                }
                if (f.branchname.value.length==0) {
                        _alertString += "- branch name missing\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($searchfield) {
                print "<h1>Modify branch</h1>";
        } else {
                print "<h1>Add branch</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<table>";
        if ($searchfield) {
                print "<tr><td>Branch code</td><td><input type=hidden 
name=searchfield value=$searchfield>$searchfield</td></tr>";
        } else {
                print "<tr><td>Branch code</td><td><input type=text 
name=searchfield size=5 maxlength=5 onBlur=toUC(this)></td></tr>";
        }
        print "<tr><td>Name</td><td><input type=text name=branchname size=40 
maxlength=80 value='$data->{'branchname'}'>&nbsp;</td></tr>";
        print "<tr><td>Adress</td><td><input type=text name=branchaddress1 
value='$data->{'branchaddress1'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><input type=text name=branchaddress2 
value='$data->{'branchaddress2'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><input type=text name=branchaddress3 
value='$data->{'branchaddress3'}'></td></tr>";
        print "<tr><td>Phone</td><td><input type=text name=branchphone 
value='$data->{'branchphone'}'></td></tr>";
        print "<tr><td>Fax</td><td><input type=text name=branchfax 
value='$data->{'branchfax'}'></td></tr>";
        print "<tr><td>E-mail</td><td><input type=text name=branchemail 
value='$data->{'branchemail'}'></td></tr>";
        print "<tr><td>Issuing</td><td><input type=text name=issuing 
value='$data->{'issuing'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
        print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace branches 
(branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail,issuing)
 values (";
        $query.= $dbh->quote($input->param('branchcode')).",";
        $query.= $dbh->quote($input->param('branchname')).",";
        $query.= $dbh->quote($input->param('branchaddress1')).",";
        $query.= $dbh->quote($input->param('branchaddress2')).",";
        $query.= $dbh->quote($input->param('branchaddress3')).",";
        $query.= $dbh->quote($input->param('branchphone')).",";
        $query.= $dbh->quote($input->param('branchfax')).",";
        $query.= $dbh->quote($input->param('branchemail')).",";
        $query.= $dbh->quote($input->param('issuing')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare("select count(*) as total from borrowers where 
branchcode='$searchfield'");
        $sth->execute;
        my $total = $sth->fetchrow_hashref;
        $sth->finish;
        print "$reqsel";
        my $sth=$dbh->prepare($reqsel);
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print mktablerow(2,'#99cc33',bold('Branch 
code'),bold("$searchfield"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=searchfield 
value='$searchfield'>";
        print "<tr><td>Branch code</td><td>$data->{'branchcode'}</td></tr>";
        print "<tr><td>&nbsp; name</td><td>$data->{'branchname'}</td></tr>";
        print "<tr><td>&nbsp; 
adress</td><td>$data->{'branchaddress1'}</td></tr>";
        print "<tr><td>&nbsp;</td><td>$data->{'branchaddress2'}</td></tr>";
        print "<tr><td>&nbsp;</td><td>$data->{'branchaddress3'}</td></tr>";
        print "<tr><td>&nbsp;phone</td><td>$data->{'branchphone'}</td></tr>";
        print "<tr><td>&nbsp; fax</td><td>$data->{'branchfax'}</td></tr>";
        print "<tr><td>&nbsp; e-mail</td><td>$data->{'branchemail'}</td></tr>";
        print "<tr><td>&nbsp; issuing</td><td>$data->{'issuing'}</td></tr>";
        if ($total->{'total'} >0) {
                print "<tr><td colspan=2 align=center><b>This record is used 
$total->{'total'} times. Deletion not possible</b></td></tr>";
                print "<tr><td colspan=2></form><form action='$script_name' 
method=post><input type=submit value=OK></form></td></tr>";
        } else {
                print "<tr><td colspan=2 align=center>CONFIRM 
DELETION</td></tr>";
                print "<tr><td><INPUT type=submit 
value='YES'></form></td><td><form action='$script_name' method=post><input 
type=submit value=NO></form></td></tr>";
        }
                                                                                
                        # 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=C4Connect;
#       my $searchfield=$input->param('branchcode');
        my $sth=$dbh->prepare($reqdel);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","searchfield",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'branches admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print mktablerow(9,'#99cc33',bold('Branch 
code'),bold('name'),bold('adress'),
        bold('phone'),bold('fax'),bold('mail'),bold('issuing'),
        '&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                #find out stats
        #       my 
($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
        #       $fines=$fines+0;
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print 
mktablerow(9,$toggle,$results->[$i]{'branchcode'},$results->[$i]{'branchname'},
                
$results->[$i]{'branchaddress1'}.$results->[$i]{'branchaddress2'}.$results->[$i]{'branchaddress3'},
                
$results->[$i]{'branchphone'},,$results->[$i]{'branchfax'},,$results->[$i]{'branchmail'},,$results->[$i]{'issuing'},
                
mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'branchcode'},'Edit'),
                
mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'branchcode'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add budget\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select * from categories where (description like 
\"$data[0]%\")";
        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;
        $dbh->disconnect;
        return ($cnt,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;
print $input->header;
#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 ($categorycode) {
                my $dbh = &C4Connect;
                my $sth=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired
 from categories where categorycode='$categorycode'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.categorycode.value.length==0) {
                        _alertString += "- categorycode missing\\n";
                }
//              alert(window.document.Aform.description.value);
                if (!(isNotNull(window.document.Aform.description,1))) {
                        _alertString += "- description missing\\n";
                }
                if (!isNum(f.upperagelimit,0)) {
                        _alertString += "- upperagelimit is not a number\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($categorycode) {
                print "<h1>Modify category</h1>";
        } else {
                print "<h1>Add category</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<input type=hidden name=checked value=0>";
        print "<table>";
        if ($categorycode) {
                print "<tr><td>Category code</td><td><input type=hidden 
name=categorycode value=$categorycode>$categorycode</td></tr>";
        } else {
                print "<tr><td>Category code</td><td><input type=text 
name=categorycode size=3 maxlength=2 onBlur=toUC(this)></td></tr>";
        }
        print "<tr><td>Description</td><td><input type=text name=description 
size=40 maxlength=80 value='$data->{'description'}'>&nbsp;</td></tr>";
        print "<tr><td>Enrolment period</td><td><input type=text 
name=enrolmentperiod value='$data->{'enrolmentperiod'}'></td></tr>";
        print "<tr><td>Upperage limit</td><td><input type=text 
name=upperagelimit value='$data->{'upperagelimit'}'></td></tr>";
        print "<tr><td>Date of birth Required</td><td><input type=text 
name=dateofbirthrequired value='$data->{'dateofbirthrequired'}'> 
(14/02/2002)</td></tr>";
        print "<tr><td>Fine type</td><td><input type=text name=finetype size=30 
maxlength=30 value='$data->{'finetype'}'></td></tr>";
        print "<tr><td>Bulk</td><td><input type=text name=bulk 
value='$data->{'bulk'}'></td></tr>";
        print "<tr><td>Enrolment fee</td><td><input type=text name=enrolmentfee 
value='$data->{'enrolmentfee'}'></td></tr>";
        print "<tr><td>Overdue notice required</td><td><input type=text 
name=overduenoticerequired value='$data->{'overduenoticerequired'}'></td></tr>";
        print "<tr><td>Issue limit</td><td><input type=text name=issuelimit 
value='$data->{'issuelimit'}'></td></tr>";
        print "<tr><td>Reserve fee</td><td><input type=text name=reservefee 
value='$data->{'reservefee'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace categories 
(categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired)
 values (";
        $query.= $dbh->quote($input->param('categorycode')).",";
        $query.= $dbh->quote($input->param('description')).",";
        $query.= $dbh->quote($input->param('enrolmentperiod')).",";
        $query.= $dbh->quote($input->param('upperagelimit')).",";
        $query.= $dbh->quote($input->param('dateofbirthrequired')).",";
        $query.= $dbh->quote($input->param('finetype')).",";
        $query.= $dbh->quote($input->param('bulk')).",";
        $query.= $dbh->quote($input->param('enrolmentfee')).",";
        $query.= $dbh->quote($input->param('issuelimit')).",";
        $query.= $dbh->quote($input->param('reservefee')).",";
        $query.= $dbh->quote($input->param('overduenoticerequired')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare("select count(*) as total from categoryitem where 
categorycode='$categorycode'");
        $sth->execute;
        my $total = $sth->fetchrow_hashref;
        print "TOTAL : $categorycode : $total->{'total'}<br>";
        $sth->finish;
        my $sth=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired
 from categories where categorycode='$categorycode'");
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print mktablerow(2,'#99cc33',bold('Category 
code'),bold("$categorycode"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=categorycode 
value='$categorycode'>";
        print "<tr><td>Description</td><td>$data->{'description'}</td></tr>";
        print "<tr><td>Enrolment 
period</td><td>$data->{'enrolmentperiod'}</td></tr>";
        print "<tr><td>Upperage 
limit</td><td>$data->{'upperagelimit'}</td></tr>";
        print "<tr><td>Date of birth 
Required</td><td>$data->{'dateofbirthrequired'}</td></tr>";
        print "<tr><td>Fine type</td><td>$data->{'finetype'}</td></tr>";
        print "<tr><td>Bulk</td><td>$data->{'bulk'}</td></tr>";
        print "<tr><td>Enrolment fee</td><td>$data->{'enrolmentfee'}</td></tr>";
        print "<tr><td>Overdue notice 
required</td><td>$data->{'overduenoticerequired'}</td></tr>";
        print "<tr><td>Issue limit</td><td>$data->{'issuelimit'}</td></tr>";
        print "<tr><td>Reserve fee</td><td>$data->{'reservefee'}</td></tr>";
        if ($total->{'total'} >0) {
                print "<tr><td colspan=2 align=center><b>This record is used 
$total->{'total'} times. Deletion not possible</b></td></tr>";
                print "<tr><td colspan=2></form><form action='$script_name' 
method=post><input type=submit value=OK></form></td></tr>";
        } else {
                print "<tr><td colspan=2 align=center>CONFIRM 
DELETION</td></tr>";
                print "<tr><td><INPUT type=submit 
value='YES'></form></td><td><form action='$script_name' method=post><input 
type=submit value=NO></form></td></tr>";
        }
                                                                                
                        # 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=C4Connect;
        my $categorycode=uc($input->param('categorycode'));
        my $query = "delete from categories where categorycode='$categorycode'";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
} else { # DEFAULT
        my @inputs=(["text","description",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'Category admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for $searchfield<p>";
        }
        print mktablehdr;
        print 
mktablerow(13,'#99cc33',bold('Category'),bold('Description'),bold('Enrolment'),bold('age
 max')
        ,bold('birth 
needed'),bold('Fine'),bold('Bulk'),bold('fee'),bold('overdue'),bold('Issue 
limit'),bold('Reserve'),'&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=0; $i < $count; $i++){
                #find out stats
        #       my 
($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
        #       $fines=$fines+0;
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print mktablerow(13,$toggle,$results->[$i]{'categorycode'},
                $results->[$i]{'description'},$results->[$i]{'enrolmentperiod'},
                
$results->[$i]{'upperagelimit'},$results->[$i]{'dateofbirthrequired'},$results->[$i]{'finetype'},
                
$results->[$i]{'bulk'},$results->[$i]{'enrolmentfee'},$results->[$i]{'overduenoticerequired'},$results->[$i]{'issuelimit'},$results->[$i]{'reservefee'},mklink("$script_name?op=add_form&categorycode=".$results->[$i]{'categorycode'},'Edit'),
                
mklink("$script_name?op=delete_confirm&categorycode=".$results->[$i]{'categorycode'},'Delete'));
        }
        print mktableft;
print <<printend
        <form action='$script_name' method=post>
        <input type=hidden name=op value=add_form>
        <input type=image src="/images/button-add-member.gif"  WIDTH=188  
HEIGHT=44  ALT="Add Category" BORDER=0 ></a><br>
        </form>
printend
        ;
} #---- END $OP eq DEFAULT
print endmenu('categorie');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select * from categories where (description like 
\"$data[0]%\")";
        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;
        $dbh->disconnect;
        return ($cnt,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;
print $input->header;
#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 ($categorycode) {
                my $dbh = &C4Connect;
                my $sth=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired
 from categories where categorycode='$categorycode'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.categorycode.value.length==0) {
                        _alertString += "- categorycode missing\\n";
                }
//              alert(window.document.Aform.description.value);
                if (!(isNotNull(window.document.Aform.description,1))) {
                        _alertString += "- description missing\\n";
                }
                if (!isNum(f.upperagelimit,0)) {
                        _alertString += "- upperagelimit is not a number\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($categorycode) {
                print "<h1>Modify category</h1>";
        } else {
                print "<h1>Add category</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<input type=hidden name=checked value=0>";
        print "<table>";
        if ($categorycode) {
                print "<tr><td>Category code</td><td><input type=hidden 
name=categorycode value=$categorycode>$categorycode</td></tr>";
        } else {
                print "<tr><td>Category code</td><td><input type=text 
name=categorycode size=3 maxlength=2 onBlur=toUC(this)></td></tr>";
        }
        print "<tr><td>Description</td><td><input type=text name=description 
size=40 maxlength=80 value='$data->{'description'}'>&nbsp;</td></tr>";
        print "<tr><td>Enrolment period</td><td><input type=text 
name=enrolmentperiod value='$data->{'enrolmentperiod'}'></td></tr>";
        print "<tr><td>Upperage limit</td><td><input type=text 
name=upperagelimit value='$data->{'upperagelimit'}'></td></tr>";
        print "<tr><td>Date of birth Required</td><td><input type=text 
name=dateofbirthrequired value='$data->{'dateofbirthrequired'}'> 
(14/02/2002)</td></tr>";
        print "<tr><td>Fine type</td><td><input type=text name=finetype size=30 
maxlength=30 value='$data->{'finetype'}'></td></tr>";
        print "<tr><td>Bulk</td><td><input type=text name=bulk 
value='$data->{'bulk'}'></td></tr>";
        print "<tr><td>Enrolment fee</td><td><input type=text name=enrolmentfee 
value='$data->{'enrolmentfee'}'></td></tr>";
        print "<tr><td>Overdue notice required</td><td><input type=text 
name=overduenoticerequired value='$data->{'overduenoticerequired'}'></td></tr>";
        print "<tr><td>Issue limit</td><td><input type=text name=issuelimit 
value='$data->{'issuelimit'}'></td></tr>";
        print "<tr><td>Reserve fee</td><td><input type=text name=reservefee 
value='$data->{'reservefee'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace categories 
(categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired)
 values (";
        $query.= $dbh->quote($input->param('categorycode')).",";
        $query.= $dbh->quote($input->param('description')).",";
        $query.= $dbh->quote($input->param('enrolmentperiod')).",";
        $query.= $dbh->quote($input->param('upperagelimit')).",";
        $query.= $dbh->quote($input->param('dateofbirthrequired')).",";
        $query.= $dbh->quote($input->param('finetype')).",";
        $query.= $dbh->quote($input->param('bulk')).",";
        $query.= $dbh->quote($input->param('enrolmentfee')).",";
        $query.= $dbh->quote($input->param('issuelimit')).",";
        $query.= $dbh->quote($input->param('reservefee')).",";
        $query.= $dbh->quote($input->param('overduenoticerequired')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare("select count(*) as total from categoryitem where 
categorycode='$categorycode'");
        $sth->execute;
        my $total = $sth->fetchrow_hashref;
        print "TOTAL : $categorycode : $total->{'total'}<br>";
        $sth->finish;
        my $sth=$dbh->prepare("select 
categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired
 from categories where categorycode='$categorycode'");
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print mktablerow(2,'#99cc33',bold('Category 
code'),bold("$categorycode"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=categorycode 
value='$categorycode'>";
        print "<tr><td>Description</td><td>$data->{'description'}</td></tr>";
        print "<tr><td>Enrolment 
period</td><td>$data->{'enrolmentperiod'}</td></tr>";
        print "<tr><td>Upperage 
limit</td><td>$data->{'upperagelimit'}</td></tr>";
        print "<tr><td>Date of birth 
Required</td><td>$data->{'dateofbirthrequired'}</td></tr>";
        print "<tr><td>Fine type</td><td>$data->{'finetype'}</td></tr>";
        print "<tr><td>Bulk</td><td>$data->{'bulk'}</td></tr>";
        print "<tr><td>Enrolment fee</td><td>$data->{'enrolmentfee'}</td></tr>";
        print "<tr><td>Overdue notice 
required</td><td>$data->{'overduenoticerequired'}</td></tr>";
        print "<tr><td>Issue limit</td><td>$data->{'issuelimit'}</td></tr>";
        print "<tr><td>Reserve fee</td><td>$data->{'reservefee'}</td></tr>";
        if ($total->{'total'} >0) {
                print "<tr><td colspan=2 align=center><b>This record is used 
$total->{'total'} times. Deletion not possible</b></td></tr>";
                print "<tr><td colspan=2></form><form action='$script_name' 
method=post><input type=submit value=OK></form></td></tr>";
        } else {
                print "<tr><td colspan=2 align=center>CONFIRM 
DELETION</td></tr>";
                print "<tr><td><INPUT type=submit 
value='YES'></form></td><td><form action='$script_name' method=post><input 
type=submit value=NO></form></td></tr>";
        }
                                                                                
                        # 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=C4Connect;
        my $categorycode=uc($input->param('categorycode'));
        my $query = "delete from categories where categorycode='$categorycode'";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
} else { # DEFAULT
        my @inputs=(["text","description",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'Category admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for $searchfield<p>";
        }
        print mktablehdr;
        print 
mktablerow(13,'#99cc33',bold('Category'),bold('Description'),bold('Enrolment'),bold('age
 max')
        ,bold('birth 
needed'),bold('Fine'),bold('Bulk'),bold('fee'),bold('overdue'),bold('Issue 
limit'),bold('Reserve'),'&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=0; $i < $count; $i++){
                #find out stats
        #       my 
($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
        #       $fines=$fines+0;
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print mktablerow(13,$toggle,$results->[$i]{'categorycode'},
                $results->[$i]{'description'},$results->[$i]{'enrolmentperiod'},
                
$results->[$i]{'upperagelimit'},$results->[$i]{'dateofbirthrequired'},$results->[$i]{'finetype'},
                
$results->[$i]{'bulk'},$results->[$i]{'enrolmentfee'},$results->[$i]{'overduenoticerequired'},$results->[$i]{'issuelimit'},$results->[$i]{'reservefee'},mklink("$script_name?op=add_form&categorycode=".$results->[$i]{'categorycode'},'Edit'),
                
mklink("$script_name?op=delete_confirm&categorycode=".$results->[$i]{'categorycode'},'Delete'));
        }
        print mktableft;
print <<printend
        <form action='$script_name' method=post>
        <input type=hidden name=op value=add_form>
        <input type=image src="/images/button-add-member.gif"  WIDTH=188  
HEIGHT=44  ALT="Add Category" BORDER=0 ></a><br>
        </form>
printend
        ;
} #---- END $OP eq DEFAULT
print endmenu('categorie');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $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;
        $dbh->disconnect;
        return ($cnt,address@hidden);
}

my $input = new CGI;
my $searchfield=$input->param('searchfield');
my $pkfield="currency";
my $reqsel="select currency,rate from currency where $pkfield='$searchfield'";
my $reqdel="delete from currency where $pkfield='$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;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 = &C4Connect;
                my $sth=$dbh->prepare("select currency,rate from currency where 
currency='$searchfield'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.currency.value.length==0) {
                        _alertString += "- currency missing\\n";
                }
                if (!isNum(f.rate)) {
                        _alertString += "- Rate not numeric\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($searchfield) {
                print "<h1>Modify currency</h1>";
        } else {
                print "<h1>Add currency</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<table>";
        if ($searchfield) {
                print "<tr><td>Currency</td><td><input type=hidden 
name=currency value=$searchfield>$searchfield</td></tr>";
        } else {
                print "<tr><td>Currency</td><td><input type=text name=currency 
size=5 maxlength=5 onBlur=toUC(this)></td></tr>";
        }
        print "<tr><td>Rate</td><td><input type=text name=rate size=10 
maxlength=10 value='$data->{'rate'}'>&nbsp;</td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
        print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace currency (currency,rate) values (";
        $query.= $dbh->quote($input->param('currency')).",";
        $query.= $dbh->quote($input->param('rate')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare("select count(*) as total from aqbooksellers 
where currency='$searchfield'");
        $sth->execute;
        my $total = $sth->fetchrow_hashref;
        $sth->finish;
        my $sth=$dbh->prepare($reqsel);
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print 
mktablerow(2,'#99cc33',bold('Currency'),bold("$searchfield"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=searchfield 
value='$searchfield'>";
        print "<tr><td>Rate</td><td>$data->{'rate'}</td></tr>";
        if ($total->{'total'} >0) {
                print "<tr><td colspan=2 align=center><b>This record is used 
$total->{'total'} times. Deletion not possible</b></td></tr>";
                print "<tr><td colspan=2></form><form action='$script_name' 
method=post><input type=submit value=OK></form></td></tr>";
        } else {
                print "<tr><td colspan=2 align=center>CONFIRM 
DELETION</td></tr>";
                print "<tr><td><INPUT type=submit 
value='YES'></form></td><td><form action='$script_name' method=post><input 
type=submit value=NO></form></td></tr>";
        }
                                                                                
                        # 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=C4Connect;
#       my $searchfield=$input->param('branchcode');
        my $sth=$dbh->prepare($reqdel);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","searchfield",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'Currencies admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print mktablerow(4,'#99cc33',bold('Currency'),bold('Rate'),
        '&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                #find out stats
        #       my 
($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
        #       $fines=$fines+0;
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print 
mktablerow(4,$toggle,$results->[$i]{'currency'},$results->[$i]{'rate'},
                
mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'currency'},'Edit'),
                
mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'currency'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add budget\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select * from itemtypes where (description like 
\"$data[0]%\") order by itemtype";
        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;
        $dbh->disconnect;
        return ($cnt,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;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 ($itemtype) {
                my $dbh = &C4Connect;
                my $sth=$dbh->prepare("select 
itemtype,description,loanlength,renewalsallowed,rentalcharge from itemtypes 
where itemtype='$itemtype'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.itemtype.value.length==0) {
                        _alertString += "- itemtype missing\\n";
                }
                if (!(isNotNull(window.document.Aform.description,1))) {
                        _alertString += "- description missing\\n";
                }
                if (!isNum(f.loanlength,0)) {
                        _alertString += "- loan length is not a number\\n";
                }
                if (!isNum(f.rentalcharge,0)) {
                        _alertString += "- loan length is not a number\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($itemtype) {
                print "<h1>Modify item type</h1>";
        } else {
                print "<h1>Add item type</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<input type=hidden name=checked value=0>";
        print "<table>";
        if ($itemtype) {
                print "<tr><td>Item type</td><td><input type=hidden 
name=itemtype value=$itemtype>$itemtype</td></tr>";
        } else {
                print "<tr><td>Item type</td><td><input type=text name=itemtype 
size=5 maxlength=3 onBlur=toUC(this)></td></tr>";
        }
        print "<tr><td>Description</td><td><input type=text name=description 
size=40 maxlength=80 value='$data->{'description'}'>&nbsp;</td></tr>";
        print "<tr><td>loan length</td><td><input type=text name=loanlength 
value='$data->{'loanlength'}'></td></tr>";
        if ($data->{'renewalsallowed'} eq 1) {
                print "<tr><td>Renewals allowed</td><td><input type=checkbox 
name=renewalsallowed checked value=1></td></tr>";
        } else {
                print "<tr><td>Renewals allowed</td><td><input type=checkbox 
name=renewalsallowed value=1></td></tr>";
        }
#       print "<tr><td>Renewals allowed</td><td><input type=text 
name=renewalsallowed value='$data->{'renewalsallowed'}'></td></tr>";
        print "<tr><td>Rental charge</td><td><input type=text name=rentalcharge 
value='$data->{'rentalcharge'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace itemtypes 
(itemtype,description,loanlength,renewalsallowed,rentalcharge) values (";
        $query.= $dbh->quote($input->param('itemtype')).",";
        $query.= $dbh->quote($input->param('description')).",";
        $query.= $dbh->quote($input->param('loanlength')).",";
        if ($input->param('renewalsallowed') ne 1) {
                $query.= "0,";
        } else {
                $query.= "1,";
        }
        $query.= $dbh->quote($input->param('rentalcharge')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare("select count(*) as total from categoryitem where 
itemtype='$itemtype'");
        $sth->execute;
        my $total = $sth->fetchrow_hashref;
        $sth->finish;
        my $sth=$dbh->prepare("select 
itemtype,description,loanlength,renewalsallowed,rentalcharge from itemtypes 
where itemtype='$itemtype'");
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print mktablerow(2,'#99cc33',bold('Item 
type'),bold("$itemtype"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=itemtype 
value='$itemtype'>";
        print "<tr><td>Description</td><td>$data->{'description'}</td></tr>";
        print "<tr><td>Loan length</td><td>$data->{'loanlength'}</td></tr>";
        print "<tr><td>Renewals 
allowed</td><td>$data->{'renewalsallowed'}</td></tr>";
        print "<tr><td>Rental charge</td><td>$data->{'rentalcharge'}</td></tr>";
        if ($total->{'total'} >0) {
                print "<tr><td colspan=2 align=center><b>This record is used 
$total->{'total'} times. Deletion not possible</b></td></tr>";
                print "<tr><td colspan=2></form><form action='$script_name' 
method=post><input type=submit value=OK></form></td></tr>";
        } else {
                print "<tr><td colspan=2 align=center>CONFIRM 
DELETION</td></tr>";
                print "<tr><td><INPUT type=submit 
value='YES'></form></td><td><form action='$script_name' method=post><input 
type=submit value=NO></form></td></tr>";
        }
                                                                                
                        # 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=C4Connect;
        my $itemtype=uc($input->param('itemtype'));
        my $query = "delete from itemtypes where itemtype='$itemtype'";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","description",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'Item types admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print 
mktablerow(7,'#99cc33',bold('Code'),bold('Description'),bold('loan<br>length'),bold('Renewals<br>allowed')
        
,bold('Rental<br>charge'),'&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                #find out stats
        #       my 
($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
        #       $fines=$fines+0;
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print mktablerow(7,$toggle,$results->[$i]{'itemtype'},
                $results->[$i]{'description'},$results->[$i]{'loanlength'},
                
$results->[$i]{'renewalsallowed'}==1?'Yes':'No',$results->[$i]{'rentalcharge'},
                
mklink("$script_name?op=add_form&itemtype=".$results->[$i]{'itemtype'},'Edit'),
                
mklink("$script_name?op=delete_confirm&itemtype=".$results->[$i]{'itemtype'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add itemtype\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select printername,printqueue,printtype from printers where 
(printername like \"$data[0]%\") order by printername";
        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;
        $dbh->disconnect;
        return ($cnt,address@hidden);
}

my $input = new CGI;
my $searchfield=$input->param('searchfield');
my $pkfield="printername";
my $reqsel="select printername,printqueue,printtype from printers where 
$pkfield='$searchfield'";
my $reqdel="delete from printers where $pkfield='$searchfield'";
#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;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 = &C4Connect;
                my $sth=$dbh->prepare("select printername,printqueue,printtype 
from printers where printername='$searchfield'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.printername.value.length==0) {
                        _alertString += "- printer name missing\\n";
                }
                if (f.printqueue.value.length==0) {
                        _alertString += "- Queue missing\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($searchfield) {
                print "<h1>Modify printer</h1>";
        } else {
                print "<h1>Add printer</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<table>";
        if ($searchfield) {
                print "<tr><td>Printer</td><td><input type=hidden 
name=printername value='$searchfield'>$searchfield</td></tr>";
        } else {
                print "<tr><td>Printer</td><td><input type=text 
name=printername size=50 maxlength=50></td></tr>";
        }
        print "<tr><td>Queue</td><td><input type=text name=printqueue size=50 
maxlength=50 value='$data->{'printqueue'}'>&nbsp;</td></tr>";
        print "<tr><td>Type</td><td><input type=text name=printtype size=50 
maxlength=50 value='$data->{'printtype'}'>&nbsp;</td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
        print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace printers (printername,printqueue,printtype) values 
(";
        $query.= $dbh->quote($input->param('printername')).",";
        $query.= $dbh->quote($input->param('printqueue')).",";
        $query.= $dbh->quote($input->param('printtype')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare($reqsel);
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print 
mktablerow(2,'#99cc33',bold('Printer'),bold("$searchfield"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=searchfield 
value='$searchfield'>";
        print "<tr><td>Queue</td><td>$data->{'printqueue'}</td></tr>";
        print "<tr><td>Type</td><td>$data->{'printtype'}</td></tr>";
        print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
        print "<tr><td><INPUT type=submit value='YES'></form></td><td><form 
action='$script_name' method=post><input type=submit 
value=NO></form></td></tr>";
                                                                                
                        # 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=C4Connect;
#       my $searchfield=$input->param('branchcode');
        my $sth=$dbh->prepare($reqdel);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","searchfield",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'Currencies admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print mktablerow(5,'#99cc33',bold('Name'),bold('Queue'),bold('Type'),
        '&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print 
mktablerow(5,$toggle,$results->[$i]{'printername'},$results->[$i]{'printqueue'},$results->[$i]{'printtype'},
                
mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'printername'},'Edit'),
                
mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'printername'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add budget\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();

--- NEW FILE ---
#!/usr/bin/perl

#script to administer the stopwords 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::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select word from stopwords where (word like \"$data[0]%\") 
order by word";
        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;
        $dbh->disconnect;
        return ($cnt,address@hidden);
}

my $input = new CGI;
my $searchfield=$input->param('searchfield');
my $pkfield="word";
my $reqsel="select word from stopwords where $pkfield='$searchfield'";
my $reqdel="delete from stopwords where $pkfield='$searchfield'";
my $offset=$input->param('offset');
my $script_name="/cgi-bin/koha/admin/stopwords.pl";

my $pagesize=20;
my $op = $input->param('op');
$searchfield=~ s/\,//g;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 = &C4Connect;
                my $sth=$dbh->prepare("select word from stopwords where 
word='$searchfield'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.word.value.length==0) {
                        _alertString += "- word missing\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($searchfield) {
                print "<h1>Modify word</h1>";
        } else {
                print "<h1>Add word</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<table>";
        if ($searchfield) {
                print "<tr><td>Word</td><td><input type=hidden name=word 
value='$searchfield'>$searchfield</td></tr>";
        } else {
                print "<tr><td>Word</td><td><input type=text name=word size=255 
maxlength=255></td></tr>";
        }
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
        print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace stopwords (word) values (";
        $query.= $dbh->quote($input->param('word')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare($reqsel);
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print 
mktablerow(2,'#99cc33',bold('Word'),bold("$searchfield"),'/images/background-mem.gif');
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=searchfield 
value='$searchfield'>";
        print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
        print "<tr><td><INPUT type=submit value='YES'></form></td><td><form 
action='$script_name' method=post><input type=submit 
value=NO></form></td></tr>";
                                                                                
                        # 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=C4Connect;
#       my $searchfield=$input->param('branchcode');
        my $sth=$dbh->prepare($reqdel);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","searchfield",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'Currencies admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend

printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print mktablerow(2,'#99cc33',bold('Word'),
        '&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print mktablerow(2,$toggle,$results->[$i]{'word'},
                
mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'word'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add budget\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();

--- NEW FILE ---
#!/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

use strict;
use C4::Output;
use CGI;
use C4::Search;
use C4::Database;

sub StringSearch  {
        my ($env,$searchstring,$type)address@hidden;
        my $dbh = &C4Connect;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my address@hidden;
        my $query="Select variable,value from systempreferences where (variable 
like \"$data[0]%\") order by variable";
        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;
        $dbh->disconnect;
        return ($cnt,address@hidden);
}

my $input = new CGI;
my $searchfield=$input->param('searchfield');
my $pkfield="variable";
my $reqsel="select variable,value from systempreferences where 
$pkfield='$searchfield'";
my $reqdel="delete from systempreferences where $pkfield='$searchfield'";
my $offset=$input->param('offset');
my $script_name="/cgi-bin/koha/admin/systempreferences.pl";

my $pagesize=20;
my $op = $input->param('op');
$searchfield=~ s/\,//g;
print $input->header;

#start the page and read in includes
print startpage();
print startmenu('admin');

################## 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 = &C4Connect;
                my $sth=$dbh->prepare("select variable,value from 
systempreferences where variable='$searchfield'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        print <<printend
        <script>
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNotNull(f,noalert) {
                if (f.value.length ==0) {
   return false;
                }
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function toUC(f) {
                var x=f.value.toUpperCase();
                f.value=x;
                return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isNum(v,maybenull) {
        var n = new Number(v.value);
        if (isNaN(n)) {
                return false;
                }
        if (maybenull==0 && v.value=='') {
                return false;
        }
        return true;
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function isDate(f) {
                var t = Date.parse(f.value);
                if (isNaN(t)) {
                        return false;
                }
        }
        
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        function Check(f) {
                var ok=1;
                var _alertString="";
                var alertString2;
                if (f.variable.value.length==0) {
                        _alertString += "- variable missing\\n";
                }
                if (f.value.value.length==0) {
                        _alertString += "- value missing\\n";
                }
                if (_alertString.length==0) {
                        document.Aform.submit();
                } else {
                        alertString2 = "Form not submitted because of the 
following problem(s)\\n";
                        alertString2 += 
"------------------------------------------------------------------------------------\\n\\n";
                        alertString2 += _alertString;
                        alert(alertString2);
                }
        }
        </SCRIPT>
printend
;#/
        if ($searchfield) {
                print "<h1>Modify pref</h1>";
        } else {
                print "<h1>Add pref</h1>";
        }
        print "<form action='$script_name' name=Aform method=post>";
        print "<input type=hidden name=op value='add_validate'>";
        print "<table>";
        if ($searchfield) {
                print "<tr><td>Variable</td><td><input type=hidden 
name=variable value='$searchfield'>$searchfield</td></tr>";
        } else {
                print "<tr><td>Variable</td><td><input type=text name=variable 
size=255 maxlength=255></td></tr>";
        }
        print "<tr><td>Value</td><td><input type=text name=value 
value='$data->{'value'}'></td></tr>";
        print "<tr><td>&nbsp;</td><td><INPUT type=button value='OK' 
onClick='Check(this.form)'></td></tr>";
        print "</table>";
        print "</form>";
;
                                                                                
                        # 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=C4Connect;
        my $query = "replace systempreferences (variable,value) values (";
        $query.= $dbh->quote($input->param('variable')).",";
        $query.= $dbh->quote($input->param('value')).")";
        my $sth=$dbh->prepare($query);
        $sth->execute;
        $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') {
        my $dbh = &C4Connect;
        my $sth=$dbh->prepare($reqsel);
        $sth->execute;
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        print mktablehdr;
        print 
mktablerow(2,'#99cc33',bold('Variable'),bold("$searchfield"),'/images/background-mem.gif');
        print "<tr><td>Value</td><td>$data->{'value'}</td></tr>";
        print "<form action='$script_name' method=post><input type=hidden 
name=op value=delete_confirmed><input type=hidden name=searchfield 
value='$searchfield'>";
        print "<tr><td colspan=2 align=center>CONFIRM DELETION</td></tr>";
        print "<tr><td><INPUT type=submit value='YES'></form></td><td><form 
action='$script_name' method=post><input type=submit 
value=NO></form></td></tr>";
                                                                                
                        # 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=C4Connect;
#       my $searchfield=$input->param('branchcode');
        my $sth=$dbh->prepare($reqdel);
        $sth->execute;
        $sth->finish;
        print "data deleted";
        print "<form action='$script_name' method=post>";
        print "<input type=submit value=OK>";
        print "</form>";
                                                                                
                        # END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
        my @inputs=(["text","searchfield",$searchfield],
                ["reset","reset","clr"]);
        print mkheadr(2,'System preferences admin');
        print mkformnotable("$script_name",@inputs);
        print <<printend
<b>Hints :</b>
2 variables are useful in this table :
<li><i>acquisitions</i>, which value may be "simple" or "normal"</li>
<li><i>autoMemberNum</i> which may be 1 or 0</li>
<br><br>
printend
        ;
        if  ($searchfield ne '') {
                print "You Searched for <b>$searchfield<b><p>";
        }
        print mktablehdr;
        print mktablerow(4,'#99cc33',bold('Variable'),bold('Value'),
        '&nbsp;','&nbsp;','/images/background-mem.gif');
        my $env;
        my ($count,$results)=StringSearch($env,$searchfield,'web');
        my $toggle="white";
        for (my $i=$offset; $i < 
($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
                if ($toggle eq 'white'){
                        $toggle="#ffffcc";
                } else {
                        $toggle="white";
                }
                print 
mktablerow(4,$toggle,$results->[$i]{'variable'},$results->[$i]{'value'},
                
mklink("$script_name?op=add_form&searchfield=".$results->[$i]{'variable'},'Edit'),
                
mklink("$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'},'Delete',''));
        }
        print mktableft;
        print "<form action='$script_name' method=post>";
        print "<input type=hidden name=op value=add_form>";
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                print mklink("$script_name?offset=".$prevpage,'&lt;&lt; Prev');
        }
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        if ($offset+$pagesize<$count) {
                my $nextpage =$offset+$pagesize;
                print mklink("$script_name?offset=".$nextpage,'Next &gt;&gt;');
        }
        print "<br><input type=image src=\"/images/button-add-member.gif\"  
WIDTH=188  HEIGHT=44  ALT=\"Add budget\" BORDER=0 ></a><br>";
        print "</form>";
} #---- END $OP eq DEFAULT
print endmenu('admin');
print endpage();




reply via email to

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