Finalized XML version for intranet
authortgarip1957 <tgarip1957>
Wed, 27 Sep 2006 21:19:21 +0000 (21:19 +0000)
committertgarip1957 <tgarip1957>
Wed, 27 Sep 2006 21:19:21 +0000 (21:19 +0000)
26 files changed:
admin/aqbookfund.pl
admin/aqbudget.pl
admin/issuingrules.pl
admin/koha-electronic.pl
admin/koha_attr.pl
authorities/authorities.pl
authorities/blinddetail-linker.pl
bookshelves/addbookbybiblionumber.pl
bookshelves/shelves.pl
catalogue/ISBDdetail.pl
cataloguing/addbiblio.pl
cataloguing/isbnsearch.pl
circ/rescirculation.pl
logout.pl
mainpage.pl
members/boraccount.pl
members/mancredit.pl
members/maninvoice.pl
members/memberentry.pl
members/moremember.pl
members/pay.pl
tools/exceptionHolidays.pl
tools/holidays.pl
tools/import.pl
tools/printerConfig.pl
tools/tools-home.pl

index bb2a297..1cfa147 100755 (executable)
@@ -1,24 +1,6 @@
 #!/usr/bin/perl
 
-#script to administer the aqbudget table
 #written 20/02/2002 by paul.poulain@free.fr
-# This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
-
-# ALGO :
-# this script use an $op to know what to do.
-# if $op is empty or none of the above values,
-#      - the default screen is build (with all records, or filtered datas).
-#      - the   user can clic on add, modify or delete record.
-# if $op=add_form
-#      - if primkey exists, this is a modification,so we read the $primkey record
-#      - builds the add/modify form
-# if $op=add_validate
-#      - the user has just send datas, so we create/modify the record
-# if $op=delete_form
-#      - we show the record having primkey=$primkey and ask for deletion validation form
-# if $op=delete_confirm
-#      - we delete the record having primkey=$primkey
-
 
 # Copyright 2000-2002 Katipo Communications
 #
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
+
+=head1 NAME
+
+aqbookfund.pl
+
+=head1 DESCRIPTION
+
+script to administer the aqbudget table.
+
+=head1 CGI PARAMETERS
+
+=over 4
+
+=item op
+this script use an C<$op> to know what to do.
+C<op> can be equal to:
+* empty or none of the above values, then
+    - the default screen is build (with all records, or filtered datas).
+       - the   user can clic on add, modify or delete record.
+* add_form, then
+       - if primkey exists, this is a modification,so we read the $primkey record
+       - builds the add/modify form
+* add_validate, then
+       - the user has just send datas, so we create/modify the record
+* delete_form, then
+       - we show the record having primkey=$primkey and ask for deletion validation form
+* delete_confirm, then
+    - we delete the record having primkey=$primkey
+
+=cut
+
 use strict;
 use CGI;
+use C4::Output;
+use List::Util qw/min/;
 use C4::Auth;
-use C4::Context;
-use C4::Acquisition;
 use C4::Koha;
+use C4::Context;
+use C4::Bookfund;
 use C4::Interface::CGI::Output;
 use C4::Search;
 use C4::Date;
 
-
-sub StringSearch  {
-       my ($env,$searchstring,%branches)=@_;
-       my $dbh = C4::Context->dbh;
-       $searchstring=~ s/\'/\\\'/g;
-       my @data=split(' ',$searchstring) if ($searchstring ne "");
-       my $count=@data;
-       my $strsth= "select bookfundid,bookfundname,bookfundgroup,branchcode from aqbookfund where 1 ";
-       $strsth.=" AND bookfundname like ? " if ($searchstring ne "");
-       if (%branches){
-               $strsth.= "AND (aqbookfund.branchcode is null " ;
-               foreach my $branchcode (keys %branches){
-                       $strsth .= "or aqbookfund.branchcode = '".$branchcode."' "; 
-               }
-               $strsth .= ") ";
-       }
-       $strsth.= "order by aqbookfund.bookfundid";
-#      warn "chaine de recherche : ".$strsth;
-       
-       my $sth=$dbh->prepare($strsth);
-       if ($searchstring){
-               $sth->execute("%$data[0]%");
-       } else {
-               $sth->execute;
-       }
-       my @results;
-       while (my $data=$sth->fetchrow_hashref){
-               push(@results,$data);
-#              warn "id ".$data->{bookfundid}." name ".$data->{bookfundname}." branchcode ".$data->{branchcode};
-       }
-       #  $sth->execute;
-       $sth->finish;
-       return (scalar(@results),\@results);
-}
-
+my $dbh = C4::Context->dbh;
 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;
+my $pagesize = 10;
+my $op = $input->param('op') || '';
 
 my ($template, $borrowernumber, $cookie)
-    = get_template_and_user({template_name => "admin/aqbookfund.tmpl",
-                            query => $input,
-                            type => "intranet",
-                            authnotrequired => 0,
-                            flagsrequired => {parameters => 1, management => 1},
-                            debug => 1,
-                            });
+    = get_template_and_user(
+        {template_name => "admin/aqbookfund.tmpl",
+         query => $input,
+         type => "intranet",
+         authnotrequired => 0,
+         flagsrequired => {parameters => 1, management => 1},
+         debug => 1,
+        }
+    );
 
 if ($op) {
-$template->param(script_name => $script_name,
-               $op              => 1); # we show only the TMPL_VAR names $op
-} else {
-$template->param(script_name => $script_name,
+    $template->param(
+        script_name => $script_name,
+        $op => 1,
+    ); # we show only the TMPL_VAR names $op
+}
+else {
+    $template->param(script_name => $script_name,
                else              => 1); # we show only the TMPL_VAR names $op
 }
 $template->param(action => $script_name);
 
-
-my @select_branch;
-my %select_branches;
-my ($branches)=GetBranches();
-
-push @select_branch,"";
-$select_branches{""}="";
-
-my $homebranch=C4::Context->userenv->{branch};
-foreach my $brnch (keys %$branches){
-       push @select_branch, $branches->{$brnch}->{'branchcode'};#
-       $select_branches{$branches->{$brnch}->{'branchcode'}} = $branches->{$brnch}->{'branchname'};
-}
-
-my $CGIbranch=CGI::scrolling_list( -name     => 'branchcode',
-                       -values   => \@select_branch,
-                       -labels   => \%select_branches,
-                       -size     => 1,
-                       -multiple => 0 );
-$template->param(CGIbranch => $CGIbranch);
+my $branches = GetBranches;
 
 ################## ADD_FORM ##################################
 # called by default. Used to create form to add or  modify a record
 if ($op eq 'add_form') {
        #---- if primkey exists, it's a modify action, so read values to modify...
-       my $data;
+       my $dataaqbookfund;
        my $header;
        if ($bookfundid) {
-               my $dbh = C4::Context->dbh;
-               my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid=?");
-               $sth->execute($bookfundid);
-               $data=$sth->fetchrow_hashref;
-               $sth->finish;
-           }
+       $dataaqbookfund = GetBookFund($bookfundid);
+       }
        if ($bookfundid) {
            $header = "Modify book fund";
            $template->param('header-is-modify-p' => 1);
@@ -151,112 +111,176 @@ if ($op eq 'add_form') {
            $template->param('header-is-add-p' => 1);
        }
        $template->param('use-header-flags-p' => 1);
-       $template->param(header => $header); # NOTE deprecated
+       $template->param(header => $header); 
        my $add_or_modify=0;
        if ($bookfundid) {
            $add_or_modify=1;
        }
        $template->param(add_or_modify => $add_or_modify);
        $template->param(bookfundid =>$bookfundid);
-       $template->param(bookfundname =>$data->{'bookfundname'});
+       $template->param(bookfundname =>$dataaqbookfund->{'bookfundname'});
+warn $dataaqbookfund->{'bookfundname'};
+        my @branchloop;
+        foreach my $branchcode (sort keys %{$branches}) {
+            my $row = {
+                branchcode => $branchcode,
+                branchname => $branches->{$branchcode}->{branchname},
+            };
+
+            if ( $bookfundid    && $dataaqbookfund->{branchcode} eq $branchcode) {
+                $row->{selected} = 1;
+            }
+
+            push @branchloop, $row;
+        }
+
+        $template->param(branches => \@branchloop);
+
+} # END $OP eq ADD_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 = C4::Context->dbh;
-       my $bookfundid=uc($input->param('bookfundid'));
-       my $sth=$dbh->prepare("delete from aqbookfund where bookfundid =?");
-       $sth->execute($bookfundid);
-       $sth->finish;
-       if ($input->param('branchcode') ne ""){
-               my $sth=$dbh->prepare("replace aqbookfund (bookfundid,bookfundname,branchcode) values (?,?,?)");
-               $sth->execute($input->param('bookfundid'),$input->param('bookfundname'),$input->param('branchcode'));
-               $sth->finish;
-       } else {
-               my $sth=$dbh->prepare("replace aqbookfund (bookfundid,bookfundname) values (?,?)");
-               $sth->execute($input->param('bookfundid'),$input->param('bookfundname'));
-               $sth->finish;
-       }
-       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=aqbookfund.pl\"></html>";
-       exit;
-                       
-                                                                               # END $OP eq ADD_VALIDATE
+elsif ($op eq 'add_validate') {
+       my $bookfundid = uc $input->param('bookfundid');
+
+    my $number = Countbookfund($bookfundid);
+
+    my $bookfund_already_exists = $number > 0 ? 1 : 0;
+
+    if ($bookfund_already_exists) {
+        my $bookfundname = $input->param('bookfundname');
+        my $branchcode = $input->param('branchcode') || undef;
+
+        ModBookFund($bookfundname,$branchcode,$bookfundid);
+    }
+    else {
+        NewBookFund(
+            $bookfundid,
+            $input->param('bookfundname'),
+            $input->param('branchcode')
+        );
+    }
+    $input->redirect('aqbookfund.pl');
+# END $OP eq ADD_VALIDATE
+}
 ################## DELETE_CONFIRM ##################################
 # called by default form, used to confirm deletion of data in DB
-} elsif ($op eq 'delete_confirm') {
-       my $dbh = C4::Context->dbh;
-       my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid=?");
-       $sth->execute($bookfundid);
-       my $data=$sth->fetchrow_hashref;
-       $sth->finish;
+
+elsif ($op eq 'delete_confirm') {
+    my $data = GetBookFund($bookfundid);
        $template->param(bookfundid => $bookfundid);
        $template->param(bookfundname => $data->{'bookfundname'});
-                                                                                                       # END $OP eq DELETE_CONFIRM
+} # END $OP eq DELETE_CONFIRM
+
+
 ################## DELETE_CONFIRMED ##################################
 # called by delete_confirm, used to effectively confirm deletion of data in DB
-} elsif ($op eq 'delete_confirmed') {
-       my $dbh = C4::Context->dbh;
-       my $bookfundid=uc($input->param('bookfundid'));
-       my $sth=$dbh->prepare("delete from aqbookfund where bookfundid=?");
-       $sth->execute($bookfundid);
-       $sth->finish;
-       $sth=$dbh->prepare("delete from aqbudget where bookfundid=?");
-       $sth->execute($bookfundid);
-       $sth->finish;
-                                                                                                       # END $OP eq DELETE_CONFIRMED
+elsif ($op eq 'delete_confirmed') {
+    DelBookFund(uc($input->param('bookfundid')));
+
+}# END $OP eq DELETE_CONFIRMED
+
+
 ################## DEFAULT ##################################
-} else { # DEFAULT
-       $template->param(scriptname => $script_name);
-       if  ($searchfield ne '') {
-               $template->param(search => 1);
-               $template->param(searchfield => $searchfield);
-       }
-       my $env;
-       my ($count,$results)=StringSearch($env,$searchfield,%select_branches);
-       my $toggle="white";
-       my @loop_data =();
-       my $dbh = C4::Context->dbh;
-       for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
-#              warn "i ".$i." offset".$offset." pagesize ".$pagesize." id ".$results->[$i]{bookfundid}." name ".$results->[$i]{bookfundname}." branchcode ".$results->[$i]{branchcode};
-               my %row_data;
-               $row_data{bookfundid} =$results->[$i]{'bookfundid'};
-               $row_data{bookfundname} = $results->[$i]{'bookfundname'};
-#              warn "".$results->[$i]{'bookfundid'}." ".$results->[$i]{'bookfundname'}." ".$results->[$i]{'branchcode'};
-               $row_data{branchname} = $select_branches{$results->[$i]{'branchcode'}};
-               my $strsth2="Select aqbudgetid,startdate,enddate,budgetamount from aqbudget where aqbudget.bookfundid = ?";
-#              my $strsth2="Select aqbudgetid,startdate,enddate,budgetamount,branchcode from aqbudget where aqbudget.bookfundid = ?";
-#              if ($homebranch){
-#                      $strsth2 .= " AND ((aqbudget.branchcode is null) OR (aqbudget.branchcode='') OR (aqbudget.branchcode= ".$dbh->quote($homebranch).")) " ;
-#              } else {
-#                      $strsth2 .= " AND (aqbudget.branchcode='') " if ((C4::Context->userenv) && (C4::Context->userenv->{flags}>1));
-#              }
-               $strsth2 .= " order by aqbudgetid";
-#              warn "".$strsth2;
-               my $sth2 = $dbh->prepare($strsth2);
-               $sth2->execute($row_data{bookfundid});
-               my @budget_loop;
-#              while (my ($aqbudgetid,$startdate,$enddate,$budgetamount,$branchcode) = $sth2->fetchrow) {
-               while (my ($aqbudgetid,$startdate,$enddate,$budgetamount) = $sth2->fetchrow) {
-                       my %budgetrow_data;
-                       $budgetrow_data{aqbudgetid} = $aqbudgetid;
-                       $budgetrow_data{startdate} = format_date($startdate);
-                       $budgetrow_data{enddate} = format_date($enddate);
-                       $budgetrow_data{budgetamount} = $budgetamount;
-#                      $budgetrow_data{branchcode} = $branchcode;
-                       push @budget_loop,\%budgetrow_data;
-               }
-               $row_data{budget} = \@budget_loop;
-               push @loop_data,\%row_data;
-       }
-       $template->param(max => (($count>$offset+$pagesize)?$offset+$pagesize:$count));
-       $template->param(min => ($offset?$offset:1));
-       $template->param(nbresults => $count);
-       $template->param(Next => ($count>$offset+$pagesize)) if ($count>$offset+$pagesize);
-       $template->param(bookfund => \@loop_data);
+else { # DEFAULT
+    my ($query, $sth);
+
+    $template->param(scriptname => $script_name);
+
+    # filters
+    my @branchloop;
+    foreach my $branchcode (sort keys %{$branches}) {
+        my $row = {
+            code => $branchcode,
+            name => $branches->{$branchcode}->{branchname},
+        };
+
+        if (defined $input->param('filter_branchcode')
+            and $input->param('filter_branchcode') eq $branchcode) {
+            $row->{selected} = 1;
+        }
+
+        push @branchloop, $row;
+    }
+
+    my @bookfundids_loop;
+    my $sth = GetBookFundsId();
+
+    while (my $row = $sth->fetchrow_hashref) {
+        if (defined $input->param('filter_bookfundid') and $input->param('filter_bookfundid') eq $row->{bookfundid}){
+            $row->{selected} = 1;
+        }
+         push @bookfundids_loop, $row;
+     }
+
+    $template->param(
+        filter_bookfundids => \@bookfundids_loop,
+        filter_branches => \@branchloop,
+        filter_bookfundname => $input->param('filter_bookfundname') || undef,
+    );
+
+    # searching the bookfunds corresponding to our filtering rules
+    my @results = SearchBookFund(
+        $input->param('filter'),
+        $input->param('filter_bookfundid'),
+        $input->param('filter_bookfundname'),
+        $input->param('filter_branchcode'),
+    );
+
+    # does the book funds have budgets?
+    my @loop_id;
+    my $sth = GetBookFundsId();
+    while (my $row = $sth->fetchrow){
+        push @loop_id, $row;
+    }
+
+    my ($id,%nb_budgets_of);
+    foreach $id (@loop_id){
+        my $number = Countbookfund($id);
+        $nb_budgets_of{$id} = $number;
+    }
+
+    # pagination informations
+    my $page = $input->param('page') || 1;
+    my @loop;
+
+    my $first = ($page - 1) * $pagesize;
+
+    # if we are on the last page, the number of the last word to display
+    # must not exceed the length of the results array
+    my $last = min(
+        $first + $pagesize - 1,
+        scalar(@results) - 1,
+    );
+
+    my $toggle = 0;
+    foreach my $result (@results[$first .. $last]) {
+        push(
+            @loop,
+            {
+                %{$result},
+                toggle => $toggle++%2,
+                branchname =>
+                    $branches->{ $result->{branchcode} }->{branchname},
+                has_budgets => defined $nb_budgets_of{ $result->{bookfundid} },
+            }
+        );
+    }
+
+    $template->param(
+            bookfund => \@loop,
+            pagination_bar => pagination_bar(
+                        $script_name,
+                        getnbpages(scalar @results, $pagesize),
+                        $page,
+                        'page'
+            )
+        );
 } #---- END $OP eq DEFAULT
-$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-               );
+$template->param(
+    intranetcolorstylesheet =>C4::Context->preference("intranetcolorstylesheet"),
+    intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+    IntranetNav => C4::Context->preference("IntranetNav"),
+    );
+
 output_html_with_http_headers $input, $cookie, $template->output;
index 1b50c79..6a6fa0f 100755 (executable)
 
 use strict;
 use CGI;
+use List::Util qw/min/;
 use C4::Date;
 use C4::Auth;
+use C4::Acquisition;
 use C4::Context;
-use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Search;
-
-
-sub StringSearch  {
-       my ($env,$searchstring,$type)=@_;
-       my $dbh = C4::Context->dbh;
-       $searchstring=~ s/\'/\\\'/g;
-       my @data=split(' ',$searchstring);
-       my $count=@data;
-       my $sth=$dbh->prepare("Select aqbudgetid,bookfundid,startdate,enddate,budgetamount from aqbudget where (bookfundid like ?) order by bookfundid,aqbudgetid");
-       $sth->execute("$data[0]%");
-       my @results;
-       my $cnt=0;
-       while (my $data=$sth->fetchrow_hashref){
-       push(@results,$data);
-       $cnt ++;
-       }
-       #  $sth->execute;
-       $sth->finish;
-       return ($cnt,\@results);
-}
+use C4::Koha;
+use C4::Output;
 
 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 $aqbudgetid=$input->param('aqbudgetid');
-my $pagesize=20;
+my $pagesize = 20;
 my $op = $input->param('op');
-$searchfield=~ s/\,//g;
 
 my ($template, $borrowernumber, $cookie)
-    = get_template_and_user({template_name => "admin/aqbudget.tmpl",
-                            query => $input,
-                            type => "intranet",
-                            authnotrequired => 0,
-                            flagsrequired => {parameters => 1},
-                            debug => 1,
-                            });
-
-if ($op) {
-$template->param(script_name => $script_name,
-                                               $op              => 1); # we show only the TMPL_VAR names $op
-} else {
-$template->param(script_name => $script_name,
-                                               else              => 1); # we show only the TMPL_VAR names $op
-}
-
-$template->param(action => $script_name);
+    = get_template_and_user(
+        {template_name => "admin/aqbudget.tmpl",
+         query => $input,
+         type => "intranet",
+         authnotrequired => 0,
+         flagsrequired => {parameters => 1},
+         debug => 1,
+     }
+    );
+
+$template->param(
+    action => $script_name,
+    DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+    script_name => $script_name,
+    $op || 'else' => 1,
+);
+
+my $dbh = C4::Context->dbh;
+my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
+$sthtemp->execute($borrowernumber);
+my ($flags, $homebranch)=$sthtemp->fetchrow;
+
 ################## ADD_FORM ##################################
 # called by default. Used to create form to add or  modify a record
 if ($op eq 'add_form') {
-       #---- if primkey exists, it's a modify action, so read values to modify...
-       my $dataaqbudget;
-       my $dataaqbookfund;
-       if ($aqbudgetid) {
-               my $dbh = C4::Context->dbh;
-               my $sth=$dbh->prepare("select aqbudgetid,bookfundname,aqbookfund.bookfundid,startdate,enddate,budgetamount from aqbudget,aqbookfund where aqbudgetid=? and aqbudget.bookfundid=aqbookfund.bookfundid");
-               $sth->execute($aqbudgetid);
-               $dataaqbudget=$sth->fetchrow_hashref;
-               $sth->finish;
-       }
-       my $header;
-       if ($aqbudgetid) {
-               $header = "Modify budget";
-       } else {
-               $header = "Add budget";
-       }
-       $template->param(header => $header);
-       if ($aqbudgetid) {
-           $template->param(modify => 1);
-           $template->param(bookfundid => $dataaqbudget->{bookfundid});
-           $template->param(bookfundname => $dataaqbudget->{bookfundname});
-       } else {
-           $template->param(bookfundid => $bookfundid,
-                                                               adding => 1);
-       }
-       $template->param(dateformat => display_date_format(),
-                                                       aqbudgetid => $dataaqbudget->{'aqbudgetid'},
-                                                       startdate => format_date($dataaqbudget->{'startdate'}),
-                                                       enddate => format_date($dataaqbudget->{'enddate'}),
-                                                       budgetamount => $dataaqbudget->{'budgetamount'}
-       );
+    my ($query, $dataaqbudget, $dataaqbookfund, $sth);
+    my $dbh = C4::Context->dbh;
+
+    #---- if primkey exists, it's a modify action, so read values to modify...
+    if ($aqbudgetid) {
+        $query = '
+SELECT aqbudgetid,
+       bookfundname,
+       aqbookfund.bookfundid,
+       startdate,
+       enddate,
+       budgetamount,
+       aqbudget.branchcode
+  FROM aqbudget
+    INNER JOIN aqbookfund ON aqbudget.bookfundid = aqbookfund.bookfundid
+  WHERE aqbudgetid = ?
+';
+        $sth=$dbh->prepare($query);
+        $sth->execute($aqbudgetid);
+        $dataaqbudget=$sth->fetchrow_hashref;
+        $sth->finish;
+    }
+
+    $query = '
+SELECT aqbookfund.branchcode,
+       branches.branchname,
+       aqbookfund.bookfundname
+  FROM aqbookfund
+    LEFT JOIN branches ON aqbookfund.branchcode = branches.branchcode
+  WHERE bookfundid = ?
+';
+    $sth=$dbh->prepare($query);
+    $sth->execute(
+        defined $aqbudgetid ? $dataaqbudget->{bookfundid} : $bookfundid,
+    );
+    $dataaqbookfund=$sth->fetchrow_hashref;
+    $sth->finish;
+
+    if (defined $aqbudgetid) {
+        $template->param(
+            bookfundid => $dataaqbudget->{'bookfundid'},
+            bookfundname => $dataaqbudget->{'bookfundname'}
+        );
+    }
+    else {
+        $template->param(
+            bookfundid => $bookfundid,
+            bookfundname => $dataaqbookfund->{bookfundname},
+        );
+    }
+
+    # Available branches
+    my @branches = ();
+
+    $query = '
+SELECT branchcode,
+       branchname
+  FROM branches
+  ORDER BY branchname
+';
+    $sth=$dbh->prepare($query);
+    $sth->execute();
+    while (my $row = $sth->fetchrow_hashref) {
+        my $branch = $row;
+
+        if (defined $dataaqbookfund->{branchcode}) {
+            $branch->{selected} =
+                $dataaqbookfund->{branchcode} eq $row->{branchcode} ? 1 : 0;
+        }
+        elsif (defined $aqbudgetid) {
+            $branch->{selected} =
+                $dataaqbudget->{branchcode} eq $row->{branchcode} ? 1 : 0;
+        }
+
+        push @branches, $branch;
+    }
+    $sth->finish;
+
+    $template->param(
+        dateformat => display_date_format(),
+        aqbudgetid => $dataaqbudget->{'aqbudgetid'},
+        startdate => format_date($dataaqbudget->{'startdate'}),
+        enddate => format_date($dataaqbudget->{'enddate'}),
+        budgetamount => $dataaqbudget->{'budgetamount'},
+        branches => \@branches,
+    );
+
+    if (defined $dataaqbookfund->{branchcode}) {
+        $template->param(
+            disable_branchselection => 1,
+            branch => $dataaqbookfund->{branchcode},
+        );
+    }
                                                                                                        # END $OP eq ADD_FORM
 ################## ADD_VALIDATE ##################################
 # called by add_form, used to insert/modify data in DB
 } elsif ($op eq 'add_validate') {
-       my $dbh = C4::Context->dbh;
-       my $sth=$dbh->prepare("replace aqbudget (aqbudgetid,bookfundid,startdate,enddate,budgetamount) values (?,?,?,?,?)");
-       $sth->execute($input->param('aqbudgetid'),$input->param('bookfundid'),
-                                               format_date_in_iso($input->param('startdate')),
-                                               format_date_in_iso($input->param('enddate')),
-                                               $input->param('budgetamount')
-                                               );
-       $sth->finish;
-        print $input->redirect("aqbookfund.pl");
-        exit;
+    my ($query, $sth);
+
+    if (defined $aqbudgetid) {
+        $query = '
+UPDATE aqbudget
+  SET bookfundid = ?,
+      startdate = ?,
+      enddate = ?,
+      budgetamount = ?,
+      branchcode = ?
+  WHERE aqbudgetid = ?
+';
+        $sth=$dbh->prepare($query);
+        $sth->execute(
+            $input->param('bookfundid'),
+            format_date_in_iso($input->param('startdate')),
+            format_date_in_iso($input->param('enddate')),
+            $input->param('budgetamount'),
+            $input->param('branch') || undef,
+            $aqbudgetid,
+        );
+        $sth->finish;
+    }
+    else {
+        $query = '
+INSERT
+  INTO aqbudget
+  (bookfundid, startdate, enddate, budgetamount, branchcode)
+  VALUES
+  (?, ?, ?, ?, ?)
+';
+        $sth=$dbh->prepare($query);
+        $sth->execute(
+            $input->param('bookfundid'),
+            format_date_in_iso($input->param('startdate')),
+            format_date_in_iso($input->param('enddate')),
+            $input->param('budgetamount'),
+            $input->param('branch') || undef,
+        );
+        $sth->finish;
+    }
+
+    $input->redirect("aqbudget.pl");
+
 # END $OP eq ADD_VALIDATE
 ################## DELETE_CONFIRM ##################################
 # called by default form, used to confirm deletion of data in DB
 } elsif ($op eq 'delete_confirm') {
        my $dbh = C4::Context->dbh;
-       my $sth=$dbh->prepare("select aqbudgetid,bookfundid,startdate,enddate,budgetamount from aqbudget where aqbudgetid=?");
+       my $sth=$dbh->prepare("select aqbudgetid,bookfundid,startdate,enddate,budgetamount,branchcode from aqbudget where aqbudgetid=?");
        $sth->execute($aqbudgetid);
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
@@ -170,54 +251,181 @@ if ($op eq 'add_form') {
                                                                                                        # END $OP eq DELETE_CONFIRMED
 ################## DEFAULT ##################################
 } else { # DEFAULT
-       if  ($searchfield ne '') {
-               $template->param(search => 1);
-               $template->param(searchfield => $searchfield);
-       }
-       my $env;
-       my ($count,$results)=StringSearch($env,$searchfield,'web');
-       my $toggle="white";
-       my @loop_data =();
-       for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
-               #find out stats
-       #       my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
-       #       $fines=$fines+0;
-               my $dataaqbookfund;
-               my $dbh = C4::Context->dbh;
-               my $sth=$dbh->prepare("select bookfundid,bookfundname from aqbookfund where bookfundid=?");
-               $sth->execute($results->[$i]{'bookfundid'});
-               $dataaqbookfund=$sth->fetchrow_hashref;
-               $sth->finish;
-               my @toggle = ();
-               my @bookfundid = ();
-               my @bookfundname = ();
-               my @startdate = ();
-               my @enddate = ();
-               my @budgetamount = ();
-               push(@toggle,$toggle);
-               push(@bookfundid,$results->[$i]{'bookfundid'});
-               push(@bookfundname,$dataaqbookfund->{'bookfundname'});
-               push(@startdate,format_date($results->[$i]{'startdate'}));
-               push(@enddate,format_date($results->[$i]{'enddate'}));
-               push(@budgetamount,$results->[$i]{'budgetamount'});
-               if ($toggle eq 'white'){
-                       $toggle="#ffffcc";
-               } else {
-                       $toggle="white";
-               }
-               while (@toggle and @bookfundid and @bookfundname and @startdate and @enddate and @budgetamount) { 
-          my %row_data;
-          $row_data{toggle} = shift @toggle;
-          $row_data{bookfundid} = shift @bookfundid;
-          $row_data{bookfundname} = shift @bookfundname;
-          $row_data{startdate} = shift @startdate;
-          $row_data{enddate} = shift @enddate;
-          $row_data{budgetamount} = shift @budgetamount;
-          push(@loop_data, \%row_data);
-       }
-       }
-       $template->param(budget => \@loop_data);
-} #---- END $OP eq DEFAULT
+    my ($query, $sth);
+
+    # create a look-up table for bookfund names from bookfund ids,
+    # instead of having on query per budget
+    my %bookfundname_of = ();
+    $query = '
+SELECT bookfundid, bookfundname
+  FROM aqbookfund
+';
+    $sth=$dbh->prepare($query);
+    $sth->execute;
+    while (my $row = $sth->fetchrow_hashref) {
+        $bookfundname_of{ $row->{bookfundid} } = $row->{bookfundname};
+    }
+    $sth->finish;
+
+    # filters
+    my $branches = GetBranches();
+    my @branchloop;
+    foreach my $branchcode (sort keys %{$branches}) {
+        my $row = {
+            code => $branchcode,
+            name => $branches->{$branchcode}->{branchname},
+        };
+
+        if (defined $input->param('filter_branchcode')
+            and $input->param('filter_branchcode') eq $branchcode) {
+            $row->{selected} = 1;
+        }
+
+        push @branchloop, $row;
+    }
+
+    my @bookfundids_loop;
+    $query = '
+SELECT bookfundid
+  FROM aqbookfund
+';
+    $sth = $dbh->prepare($query);
+    $sth->execute();
+    while (my $row = $sth->fetchrow_hashref) {
+        if (defined $input->param('filter_bookfundid')
+            and $input->param('filter_bookfundid') eq $row->{bookfundid}) {
+            $row->{selected} = 1;
+        }
+
+        push @bookfundids_loop, $row;
+    }
+    $sth->finish;
+
+    $template->param(
+        filter_bookfundids => \@bookfundids_loop,
+        filter_branches => \@branchloop,
+        filter_amount => $input->param('filter_amount') || undef,
+        filter_startdate => $input->param('filter_startdate') || undef,
+        filter_enddate => $input->param('filter_enddate') || undef,
+    );
+
+    my %sign_label_of = (
+        '=' => 'equal',
+        '>=' => 'superior',
+        '<=' => 'inferior',
+    );
 
+    foreach my $field (qw/startdate enddate amount/) {
+        my $param = 'filter_'.$field.'_sign';
+
+        foreach my $sign (keys %sign_label_of) {
+            if ($input->param($param) eq $sign) {
+                $template->param(
+                    $param.'_'.$sign_label_of{$sign}.'_selected' => 1,
+                );
+            }
+        }
+    }
+
+    # Search all available budgets
+    $query = '
+SELECT aqbudgetid,
+       bookfundid,
+       startdate,
+       enddate,
+       budgetamount,
+       branchcode
+  FROM aqbudget
+  WHERE 1 = 1';
+
+    my @bindings;
+
+    if ($input->param('filter_bookfundid')) {
+        $query.= '
+    AND bookfundid = ?
+';
+        push @bindings, $input->param('filter_bookfundid');
+    }
+    if ($input->param('filter_branchcode')) {
+        $query.= '
+    AND branchcode = ?
+';
+        push @bindings, $input->param('filter_branchcode');
+    }
+    if ($input->param('filter_startdate')) {
+        $query.= '
+    AND startdate '.$input->param('filter_startdate_sign').' ?
+';
+        push @bindings, format_date_in_iso($input->param('filter_startdate'));
+    }
+    if ($input->param('filter_enddate')) {
+        $query.= '
+    AND enddate '.$input->param('filter_enddate_sign').' ?
+';
+        push @bindings, format_date_in_iso($input->param('filter_enddate'));
+    }
+    if ($input->param('filter_amount')) {
+        $query.= '
+    AND budgetamount '.$input->param('filter_amount_sign').' ?
+';
+        # the amount must be a quantity, with 2 digits after the decimal
+        # separator
+        $input->param('filter_amount') =~ m{(\d* (?:\.\d{,2})? )}xms;
+        my ($amount) = $1;
+        push @bindings, $amount;
+    }
+
+    $query.= '
+  ORDER BY bookfundid, aqbudgetid
+';
+    $sth = $dbh->prepare($query);
+    $sth->execute(@bindings);
+    my @results;
+    while (my $row = $sth->fetchrow_hashref){
+        push @results, $row;
+    }
+    $sth->finish;
+
+    # filter budgets depending on the pagination
+    my $page = $input->param('page') || 1;
+    my $first = ($page - 1) * $pagesize;
+
+    # if we are on the last page, the number of the last word to display
+    # must not exceed the length of the results array
+    my $last = min(
+        $first + $pagesize - 1,
+        scalar @results - 1,
+    );
+
+    my $toggle = 0;
+    my @loop;
+    foreach my $result (@results[$first .. $last]) {
+        push(
+            @loop,
+            {
+                %{$result},
+                toggle => $toggle++%2,
+                bookfundname => $bookfundname_of{ $result->{'bookfundid'} },
+                branchname => $branches->{ $result->{branchcode} }->{branchname},
+                startdate => format_date($result->{startdate}),
+                enddate => format_date($result->{enddate}),
+            }
+        );
+    }
+
+    $template->param(
+        budget => \@loop,
+        pagination_bar => pagination_bar(
+            $script_name,
+            getnbpages(scalar @results, $pagesize),
+            $page,
+            'page'
+        )
+    );
+} #---- END $OP eq DEFAULT
+$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
 output_html_with_http_headers $input, $cookie, $template->output;
 
index 5f8281f..18cac28 100755 (executable)
@@ -22,7 +22,6 @@ use CGI;
 use C4::Context;
 use C4::Output;
 use C4::Auth;
-use C4::Output;
 use C4::Koha;
 use C4::Interface::CGI::Output;
 
@@ -98,7 +97,7 @@ if ($op eq 'save') {
        }
 
 }
-my $branches = getbranches;
+my $branches = GetBranches;
 my @branchloop;
 foreach my $thisbranch (keys %$branches) {
        my $selected = 1 if $thisbranch eq $branch;
index f402bc0..f105451 100644 (file)
@@ -67,7 +67,7 @@ if ($op eq 'add_form') {
        my $href        = $cgi->param('href');
        my $section     = $cgi->param('section');
        add_opac_electronic($title, $edata, $lang,$image, $href,$section);
-       print $cgi->redirect('/cgi-bin/koha/admin/opac-electronic.pl');
+       print $cgi->redirect('/cgi-bin/koha/admin/koha-electronic.pl');
 
 } elsif ($op eq 'edit') {
 # warn "edit";
@@ -79,13 +79,13 @@ if ($op eq 'add_form') {
        my $href        = $cgi->param('href');
        my $section     = $cgi->param('section');
        upd_opac_electronic($id, $title, $edata, $lang,$image,$href,$section);
-       print $cgi->redirect('/cgi-bin/koha/admin/opac-electronic.pl');
+       print $cgi->redirect('/cgi-bin/koha/admin/koha-electronic.pl');
 
 } elsif ($op eq 'del') {
 # warn "del";
        my @ids = $cgi->param('ids');
        del_opac_electronic(join ",", @ids);
-       print $cgi->redirect('/cgi-bin/koha/admin/opac-electronic.pl');
+       print $cgi->redirect('/cgi-bin/koha/admin/koha-electronic.pl');
 
 } else { 
 # warn "else";
index 2182698..088abfa 100644 (file)
@@ -70,7 +70,7 @@ if ($op eq 'add_form') {
        #---- if primkey exists, it's a modify action, so read values to modify...
        my $data;
        if ($id) {
-               $sth=$dbh->prepare("select id,marctokoha,attr,liblibrarian,sorts,recordtype,tagfield,tagsubfield,opacshow,intrashow from koha_attr where id=? ");
+               $sth=$dbh->prepare("select id,kohafield,attr,extraattr,label,sorts,recordtype,tagfield,tagsubfield,opacshow,intrashow,facets_label from koha_attr where id=? ");
                $sth->execute($id);
                $data=$sth->fetchrow_hashref;
                $sth->finish;
@@ -116,19 +116,21 @@ if ($op eq 'add_form') {
                        );
        
        if ($searchfield) {
-               $template->param(action => "Modify tag",id=>$id ,searchfield => "<input type=\"hidden\" name=\"marctokoha\" value=\"$searchfield\" />$searchfield");
+               $template->param(action => "Modify tag",id=>$id ,searchfield => "<input type=\"hidden\" name=\"kohafield\" value=\"$searchfield\" />$searchfield");
                $template->param('heading-modify-tag-p' => 1);
        } else {
                $template->param(action => "Add tag",
-                                                               searchfield => "<input type=\"text\" name=\"marctokoha\" size=\"40\" maxlength=\"80\" />");
+                                                               searchfield => "<input type=\"text\" name=\"kohafield\" size=\"40\" maxlength=\"80\" />");
                $template->param('heading-add-tag-p' => 1);
        }
        $template->param('use-heading-flags-p' => 1);
-       $template->param(liblibrarian => $data->{'liblibrarian'},
+       $template->param(label => $data->{'label'},
                        attr=> $data->{'attr'},
+                       extraattr=>$data->{'extraattr'},
                        recordtype=>$recordlist,
                        tagfield=>$taglist,
                        tagsubfield=>$tagsublist,
+                       facets_label=>$data->{'facets_label'},
                        sorts => CGI::checkbox(-name=>'sorts',
                                                -checked=> $data->{'sorts'}?'checked':'',
                                                -value=> 1,
@@ -153,34 +155,36 @@ if ($op eq 'add_form') {
 } elsif ($op eq 'add_validate') {
 my $id       =$input->param('id');
 
-       $sth=$dbh->prepare("replace koha_attr  set id=?,marctokoha=?,attr=?,liblibrarian=?,sorts=?,recordtype=?,tagfield=?,tagsubfield=? ,opacshow=?,intrashow=? ");
+       $sth=$dbh->prepare("replace koha_attr  set id=?,kohafield=?,attr=?,extraattr=?,label=?,sorts=?,recordtype=?,tagfield=?,tagsubfield=? ,opacshow=?,intrashow=? ,facets_label=?");
 
        
-       my $marctokoha       =$input->param('marctokoha');
+       my $kohafield       =$input->param('kohafield');
        my $attr       =$input->param('attr');
-       my $liblibrarian  = $input->param('liblibrarian');
+       my $extraattr       =$input->param('extraattr');
+       my $label  = $input->param('label');
        my $sorts =$input->param('sorts');
        my $opacshow =$input->param('opacshow');
        my $intrashow =$input->param('intrashow');
        my $recordtype =$input->param('recordtype');
        my $tagfield =$input->param('tagfield');
        my $tagsubfield =$input->param('tagsubfield');
+       my $facets_label =$input->param('facets_label');
        unless (C4::Context->config('demo') eq 1) {
-               $sth->execute( $id,$marctokoha,$attr,$liblibrarian,$sorts?1:0,$recordtype,$tagfield,$tagsubfield,$opacshow?1:0,$intrashow?1:0);
+               $sth->execute( $id,$kohafield,$attr,$extraattr,$label,$sorts?1:0,$recordtype,$tagfield,$tagsubfield,$opacshow?1:0,$intrashow?1:0,$facets_label);
        }
        $sth->finish;
-       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha_attr.pl?searchfield=$marctokoha\"></html>";
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha_attr.pl?searchfield=$kohafield\"></html>";
 
        exit;
                                                                                                        # END $OP eq ADD_VALIDATE
 ################## DELETE_CONFIRM ##################################
 # called by default form, used to confirm deletion of data in DB
 } elsif ($op eq 'delete_confirm') {
-       $sth=$dbh->prepare("select id,marctokoha,liblibrarian,recordtype from koha_attr where id=? ");
+       $sth=$dbh->prepare("select id,kohafield,label,recordtype from koha_attr where id=? ");
                $sth->execute($id);
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
-       $template->param(liblibrarian => $data->{'liblibrarian'}."/". $data->{'recordtype'},id=>$data->{'id'},
+       $template->param(label => $data->{'label'}."/". $data->{'recordtype'},id=>$data->{'id'},
                                                        searchfield => $searchfield,
                                                        );
                                                                                                        # END $OP eq DELETE_CONFIRM
@@ -202,7 +206,7 @@ my $id       =$input->param('id');
        my $cnt=0;
        if ($dspchoice) {
                #here, user only wants used tags/subfields displayed
-               my $sth=$dbh->prepare("Select * from koha_attr where tagfield <>'' and marctokoha >= ? ");
+               my $sth=$dbh->prepare("Select * from koha_attr where tagfield <>'' and kohafield >= ? ");
                #could be ordoned by tab
                $sth->execute($searchfield);
 
@@ -225,17 +229,19 @@ my $id       =$input->param('id');
                        }
                        my %row_data;  # get a fresh hash for the row data
                        $row_data{id} = $results[$i]->{'id'};
-                       $row_data{marctokoha} = $results[$i]->{'marctokoha'};
-                       $row_data{liblibrarian} = $results[$i]->{'liblibrarian'};
+                       $row_data{kohafield} = $results[$i]->{'kohafield'};
+                       $row_data{label} = $results[$i]->{'label'};
                        $row_data{sorts} = $results[$i]->{'sorts'};
                        $row_data{attr} = $results[$i]->{'attr'};
+                       $row_data{extraattr} = $results[$i]->{'extraattr'};
                        $row_data{recordtype} = $results[$i]->{'recordtype'};
                        $row_data{tagfield} = $results[$i]->{'tagfield'};
                        $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
                        $row_data{opacshow} = $results[$i]->{'opacshow'};
                        $row_data{intrashow} = $results[$i]->{'intrashow'};
-                       $row_data{edit} = "$script_name?op=add_form&amp;searchfield=".$results[$i]->{'marctokoha'}."&amp;id=".$results[$i]->{'id'};
-                       $row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'marctokoha'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{facets_label} = $results[$i]->{'facets_label'};
+                       $row_data{edit} = "$script_name?op=add_form&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
+                       $row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{'kohafield'}."&amp;id=".$results[$i]->{'id'};
                        $row_data{toggle} = $toggle;
                        push(@loop_data, \%row_data);
                        $i++;
@@ -257,15 +263,17 @@ my $id       =$input->param('id');
                        }
                        my %row_data;  # get a fresh hash for the row data
                        $row_data{id} = $results[$i]->{'id'};
-                       $row_data{marctokoha} = $results[$i]->{marctokoha};
-                       $row_data{liblibrarian} = $results[$i]->{liblibrarian};
-                       $row_data{sorts} = $results[$i]->{sorts};
-                       $row_data{opacshow} = $results[$i]->{'opacshow'};
-                       $row_data{intrashow} = $results[$i]->{'intrashow'};
-                       $row_data{attr} = $results[$i]->{attr};
+                       $row_data{kohafield} = $results[$i]->{'kohafield'};
+                       $row_data{label} = $results[$i]->{'label'};
+                       $row_data{sorts} = $results[$i]->{'sorts'};
+                       $row_data{attr} = $results[$i]->{'attr'};
+                       $row_data{extraattr} = $results[$i]->{'extraattr'};
                        $row_data{recordtype} = $results[$i]->{'recordtype'};
                        $row_data{tagfield} = $results[$i]->{'tagfield'};
                        $row_data{tagsubfield} = $results[$i]->{'tagsubfield'};
+                       $row_data{opacshow} = $results[$i]->{'opacshow'};
+                       $row_data{intrashow} = $results[$i]->{'intrashow'};
+                       $row_data{facets_label} = $results[$i]->{'facets_label'};
                        $row_data{edit} = "$script_name?op=add_form&amp;searchfield=".$results[$i]->{marctokoha}."&amp;id=".$results[$i]->{'id'};
                        $row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results[$i]->{marctokoha}."&amp;id=".$results[$i]->{'id'};
                        $row_data{toggle} = $toggle;
@@ -305,7 +313,7 @@ output_html_with_http_headers $input, $cookie, $template->output;
 #
 sub StringSearch  {
        my ($dbh,$searchstring)=@_;
-       my $sth=$dbh->prepare("Select * from koha_attr  where marctokoha >=?  order by marctokoha");
+       my $sth=$dbh->prepare("Select * from koha_attr  where kohafield >=?  order by kohafield");
        $sth->execute($searchstring);
        my @dataresults;
        while (my $data=$sth->fetchrow_hashref){
index 141192c..cd6f43a 100755 (executable)
@@ -162,6 +162,7 @@ sub build_tabs  ($$$;$){
     my $tag;
     my $i=0;
 my $id=100;
+my ($authidtagfield,$authidtagsubfield)=MARCfind_marc_from_kohafield("authid","authorities");
        my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
                from authorised_values
                where category=? order by lib");
@@ -191,7 +192,9 @@ my %built;
                        my ($ind1,$ind2);
                        
                 if ($tag>9){
-                       foreach my $data (@$author){
+                       next if ($tag eq $authidtagfield); #we do not want authid to duplicate
+
+                       foreach my $data (@$author){                                                    
                                        $hiddenrequired=0;
                                        my @subfields_data;
                                        undef %definedsubfields;
@@ -232,7 +235,7 @@ my %built;
                                        foreach my $subfield (sort( keys %{$tagslib->{$tag}})) {
                                                next if (length $subfield !=1);
                                                next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                               next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1")  ); #check for visibility flag
+                                               next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) >1)  ); #check for visibility flag
                                                next if ($definedsubfields{$tag.$subfield} );
                                                push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
                                                $definedsubfields{$tag.$subfield}=1;
@@ -253,6 +256,8 @@ my %built;
                        
                        }#eachdata
                }else{ ## tag <10
+                       next if ($tag eq $authidtagfield); #we do not want authid to duplicate
+
                                if ($tag eq "000" || $tag eq "LDR"){
                                        my $subfield="@";
                                        next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
@@ -274,28 +279,19 @@ my %built;
                                 foreach my $control (@$controlfields){
                                        my $subfield="@";
                                        next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
+                                       next if ($tagslib->{$tag} eq $authidtagfield);
                                        my @subfields_data;
                                        if ($control->{'tag'} eq $tag){
-                                       $hiddenrequired=0;
-                                       $tagdefined{$tag}=1 ;
-                                        if ($built{$tag}==1){$hiddenrequired=1;}
-                                       my $value=$control->{'content'} ;
-                                       $definedsubfields{$tag.'@'}=1;
-                                       push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id));                                    
-                                       $i++;
-                                       
-                                          $built{$tag}=1;
-                                       if ($hiddenrequired && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) {
-                                               my @hiddensubfields_data;
-                                               my %tag_data;
-                                               push(@hiddensubfields_data, &create_input('','','',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
-                                               $tag_data{tag} = '';
-                                               $tag_data{tag_lib} = '';
-                                               $tag_data{subfield_loop} = \@hiddensubfields_data;
-                                               $tag_data{fixedfield} = 1;
-                                               push (@loop_data, \%tag_data);
+                                               $hiddenrequired=0;
+                                               $tagdefined{$tag}=1;
+                                                if ($built{$tag}==1){$hiddenrequired=1;}
+                                               my $value=$control->{'content'} ;
+                                               $definedsubfields{$tag.'@'}=1;
+                                               push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id));                                    
                                                $i++;
-                                       }
+                                       
+                                               $built{$tag}=1;
+                                       ###hiddenrequired
                                        if ($#subfields_data >= 0) {
                                                my %tag_data;
                                                $tag_data{tag} = $tag;
@@ -319,8 +315,7 @@ my %built;
                                                next if ($tagdefined{$tag} );
                                                next if (length $subfield !=1);
                                                next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                               next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1")  ); #check for visibility flag
-                                               
+                                               next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) > 1) ); #check for visibility flag
                                                push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
                                                $tagdefined{$tag.$subfield}=1;
                                                $i++;
@@ -348,7 +343,7 @@ my %built;
                                                foreach my $subfield (sort( keys %{$tagslib->{$tag}})) {
                                                next if (length $subfield !=1);
                                                next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                               next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1")  ); #check for visibility flag
+                                               next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) >1)  ); #check for visibility flag
                                                $addedfield=""; 
                                                push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
                                                $i++;
@@ -373,7 +368,7 @@ my %built;
                                my @subfields_data;
                                foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
                                        next if (length $subfield !=1);
-                                       next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1")  ); #check for visibility flag
+                                       next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) >1)  ); #check for visibility flag
                                        next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
                                        push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
                                        $i++;
@@ -471,8 +466,8 @@ my ($oldauthtypetagfield,$oldauthtypetagsubfield);
 $is_a_modif=0;
 if ($authid) {
        $is_a_modif=1;
-       ($oldauthnumtagfield,$oldauthnumtagsubfield) = MARCfind_marc_from_kohafield("auth_authid","authorities");
-       ($oldauthtypetagfield,$oldauthtypetagsubfield) = MARCfind_marc_from_kohafield("auth_authtypecode","authorities");
+       ($oldauthnumtagfield,$oldauthnumtagsubfield) = MARCfind_marc_from_kohafield("authid","authorities");
+       ($oldauthtypetagfield,$oldauthtypetagsubfield) = MARCfind_marc_from_kohafield("authtypecode","authorities");
 }
 
 #------------------------------------------------------------------------------------------------------------------------------
@@ -492,11 +487,14 @@ if ($op eq "add") {
 eval{
  $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);       
 };
+
  if ($@){
 warn $@;
  $template->param(error             =>1,xmlerror=>1,);
 goto FINAL;
   };   # check for a duplicate
+###Authorities need the XML header unlike biblios
+$xml='<?xml version="1.0" encoding="UTF-8"?>'.$xml;
   my $xmlhash=XML_xml2hash_onerecord($xml);
        my ($duplicateauthid,$duplicateauthvalue) = C4::AuthoritiesMarc::FindDuplicateauth($xmlhash,$authtypecode) if ($op eq "add") && (!$is_a_modif);
 #warn "duplicate:$duplicateauthid,$duplicateauthvalue";        
@@ -505,9 +503,9 @@ goto FINAL;
        if (!$duplicateauthid or $confirm_not_duplicate) {
 # warn "noduplicate";
                if ($is_a_modif ) {     
-                       $authid=AUTHmodauthority($dbh,$authid,$xmlhash,$authtypecode,1);                
+                       $authid=AUTHmodauthority($dbh,$authid,$xmlhash,$authtypecode);
                } else {
-               ($authid) = AUTHaddauthority($dbh,$xmlhash,$authid,$authtypecode);
+               $authid = AUTHaddauthority($dbh,$xmlhash,'',$authtypecode);
 
                }
        # now, redirect to detail page
@@ -540,6 +538,7 @@ FINAL:
        my @ind_tag = $input->param('ind_tag');
        my @indicator = $input->param('indicator');
        my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
+       $xml='<?xml version="1.0" encoding="UTF-8"?>'.$xml;
        my $xmlhash=XML_xml2hash_onerecord($xml);
        # adding an empty field
        build_tabs ($template, $xmlhash, $dbh,$addedfield);
index 599093a..f9e2763 100644 (file)
@@ -54,7 +54,7 @@ my $index = $query->param('index');
 my $authtypecode=$query->param('authtypecode');
  $authtypecode = &AUTHfind_authtypecode($dbh,$authid) if !$authtypecode;
 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
-my ($linkidfield,$linkidsubfield)=MARCfind_marc_from_kohafield("auth_linkid","authorities");
+my ($linkidfield,$linkidsubfield)=MARCfind_marc_from_kohafield("linkid","authorities");
 my $auth_type = AUTHgetauth_type($authtypecode);
 
 my $record =XMLgetauthorityhash($dbh,$authid);
index 907ca8b..9221ef1 100755 (executable)
@@ -25,12 +25,11 @@ use strict;
 use C4::Search;
 use C4::Biblio;
 use CGI;
-use C4::Output;
 use C4::BookShelves;
 use C4::Circulation::Circ2;
 use C4::Auth;
 use C4::Interface::CGI::Output;
-use HTML::Template;
+
 
 my $env;
 my $query = new CGI;
@@ -85,6 +84,9 @@ if ($shelfnumber) {
        output_html_with_http_headers $query, $cookie, $template->output;
 }
 # $Log$
+# Revision 1.5  2006/09/27 21:19:21  tgarip1957
+# Finalized XML version for intranet
+#
 # Revision 1.4  2006/07/04 14:36:51  toins
 # Head & rel_2_2 merged
 #
index 656bcea..15f8d3e 100755 (executable)
 use strict;
 use C4::Search;
 use CGI;
-use C4::Output;
 use C4::BookShelves;
 use C4::Circulation::Circ2;
 use C4::Auth;
 use C4::Interface::CGI::Output;
-use HTML::Template;
+
 
 my $env;
 my $query = new CGI;
@@ -194,6 +193,9 @@ sub viewshelf {
 
 #
 # $Log$
+# Revision 1.10  2006/09/27 21:19:21  tgarip1957
+# Finalized XML version for intranet
+#
 # Revision 1.9  2006/07/04 14:36:51  toins
 # Head & rel_2_2 merged
 #
index e6b39e1..8bb91bc 100755 (executable)
@@ -37,30 +37,27 @@ from koha style DB.  Automaticaly maps to marc biblionumber).
 
 
 use strict;
-require Exporter;
+
 use C4::Auth;
 use C4::Context;
-use C4::Output;
+use C4::AuthoritiesMarc;
 use C4::Interface::CGI::Output;
 use CGI;
 use C4::Search;
-use MARC::Record;
 use C4::Biblio;
 use C4::Acquisition;
-use HTML::Template;
+use C4::Koha;
 
 my $query=new CGI;
 
 my $dbh=C4::Context->dbh;
 
-my $biblionumber=$query->param('bib');
-my $bibid = $query->param('bibid');
-$bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber) unless $bibid;
-$biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid) unless $biblionumber;
-my $itemtype = &MARCfind_frameworkcode($dbh,$bibid);
+my $biblionumber=$query->param('biblionumber');
+
+my $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber);
 my $tagslib = &MARCgettagslib($dbh,1,$itemtype);
 
-my $record =MARCgetbiblio($dbh,$bibid);
+my $record =XMLgetbibliohash($dbh,$biblionumber);
 # open template
 my ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => "catalogue/ISBDdetail.tmpl",
@@ -71,32 +68,29 @@ my ($template, $loggedinuser, $cookie)
                             });
 
 my $ISBD = C4::Context->preference('ISBD');
-# my @blocs = split /\@/,$ISBD;
-# my @fields = $record->fields();
 my $res;
-# foreach my $bloc (@blocs) {
-#      $bloc =~ s/\n//g;
        my $bloc = $ISBD;
        my $blocres;
        foreach my $isbdfield (split /#/,$bloc) {
-#              $isbdfield= /(.?.?.?)/;
                $isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
                my $fieldvalue=$1;
                my $textbefore=$2;
                my $analysestring=$3;
                my $textafter=$4;
-#              warn "==> $1 / $2 / $3 / $4";
-#              my $fieldvalue=substr($isbdfield,0,3);
                if ($fieldvalue>0) {
-       #               warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
-#                      warn "FV : $fieldvalue";
                        my $hasputtextbefore=0;
-                       foreach my $field ($record->field($fieldvalue)) {
+                       
                                my $calculated = $analysestring;
-                               my $tag = $field->tag();
+                               my $tag = $fieldvalue;
                                if ($tag<10) {
+                               my $value=XML_readline_onerecord($record,"","",$tag);
+                               my $subfieldcode = "@";
+                                               my $subfieldvalue = get_authorised_value_desc($tag, $subf[$i][0], $value, '', $dbh);;
+                                               my $tagsubf = $tag.$subfieldcode;
+                                               $calculated =~ s/\{(.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue\{$1$tagsubf$2\}$2/g;
+                                       
                                } else {
-                                       my @subf = $field->subfields;
+                                       my @subf = XML_readline_withtags($record,"","",$tag);
                                        for my $i (0..$#subf) {
                                                my $subfieldcode = $subf[$i][0];
                                                my $subfieldvalue = get_authorised_value_desc($tag, $subf[$i][0], $subf[$i][1], '', $dbh);;
@@ -112,7 +106,7 @@ my $res;
                                        $calculated =~ s/^( |;|:|\.|-)*//g;
                                        $blocres.=$calculated;
                                }
-                       }
+                       
                        $blocres .=$textafter if $hasputtextbefore;
                } else {
                        $blocres.=$isbdfield;
index bc29cd0..183ae63 100755 (executable)
@@ -116,7 +116,7 @@ sub MARCfindbreeding {
                        }       
                $record->insert_fields_ordered($newfield);
                }
-       my $xml=  $record->as_xml_record();
+       my $xml=MARC::File::XML::record($record);
        $xml=Encode::encode('utf8',$xml);
        my $xmlhash=XML_xml2hash_onerecord($xml);
                return $xmlhash,$encoding;
@@ -246,6 +246,8 @@ my $id=100;
        my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
                from authorised_values
                where category=? order by lib");
+my ($biblionumtagfield,$biblionumtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblionumber","biblios");
+
 my $biblio;
 my $controlfields;
 my $leader;
@@ -262,6 +264,7 @@ for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
 
                my @loop_data = ();
        foreach my $tag (sort(keys (%{$tagslib}))) {
+       next if ($tag eq $biblionumtagfield);## Otherwise biblionumber will be duplicated on modifs if user has set visibility to true
                        my $indicator;
                                # if MARC::Record is not empty => use it as master loop, then add missing subfields that should be in the tab.
                                # if MARC::Record is empty => use tab as master loop.
@@ -272,19 +275,15 @@ for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
                
                        my %tagdefined;
                        my %definedsubfields;
-                       my $hiddenrequired;
+                       
                        my ($ind1,$ind2);
                        
                 if ($tag>9){
                        foreach my $data (@$biblio){
-                                       $hiddenrequired=0;
                                        my @subfields_data;
                                        undef %definedsubfields;
                                 if ($data->{'tag'} eq $tag){
                                        $tagdefined{$tag}=1 ;
-                                          if ($built{$tag}==1){
-                                               $hiddenrequired=1;
-                                           }
                                            $ind1="  ";
                                              $ind2="  ";               
                                              foreach my $subfieldcode ( $data->{'subfield'}){
@@ -301,17 +300,7 @@ for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
                                            $ind1=$data->{'ind1'};
                                            $ind2=      $data->{'ind2'};
                                          
-                                       if ($hiddenrequired && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) {
-                                               my @hiddensubfields_data;
-                                               my %tag_data;
-                                               push(@hiddensubfields_data, &create_input('','','',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
-                                               $tag_data{tag} = '';
-                                               $tag_data{tag_lib} = '';
-                                               $tag_data{indicator} = '';
-                                               $tag_data{subfield_loop} = \@hiddensubfields_data;
-                                               push (@loop_data, \%tag_data);
-                                               $i++;
-                                       }
+                                       
                                        # now, loop again to add parameter subfield that are not in the MARC::Record
                                        
                                        foreach my $subfield (sort( keys %{$tagslib->{$tag}})) {
@@ -361,26 +350,14 @@ for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
                                        next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
                                        my @subfields_data;
                                        if ($control->{'tag'} eq $tag){
-                                       $hiddenrequired=0;
                                        $tagdefined{$tag}=1 ;
-                                        if ($built{$tag}==1){$hiddenrequired=1;}
                                        my $value=$control->{'content'} ;
                                        $definedsubfields{$tag.'@'}=1;
                                        push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id));                                    
                                        $i++;
                                        
                                           $built{$tag}=1;
-                                       if ($hiddenrequired && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) {
-                                               my @hiddensubfields_data;
-                                               my %tag_data;
-                                               push(@hiddensubfields_data, &create_input('','','',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
-                                               $tag_data{tag} = '';
-                                               $tag_data{tag_lib} = '';
-                                               $tag_data{subfield_loop} = \@hiddensubfields_data;
-                                               $tag_data{fixedfield} = 1;
-                                               push (@loop_data, \%tag_data);
-                                               $i++;
-                                       }
+                                       
                                        if ($#subfields_data >= 0) {
                                                my %tag_data;
                                                $tag_data{tag} = $tag;
@@ -528,7 +505,7 @@ my $breedingid = $input->param('breedingid');
 my $z3950 = $input->param('z3950');
 my $op = $input->param('op');
 my $duplicateok = $input->param('duplicateok');
-
+my $suggestionid=$input->param('suggestionid');
 my $frameworkcode = $input->param('frameworkcode');
 my $dbh = C4::Context->dbh;
 my $biblionumber;
@@ -575,7 +552,11 @@ $xmlhash=XML_xml2hash_onerecord($record) if ($biblionumber);
 $frameworkcode=MARCfind_frameworkcode( $dbh, $biblionumber );
 ###########
 $tagslib = &MARCgettagslib($dbh,1,$frameworkcode);
-
+if ($suggestionid && !$biblionumber){
+my $data=GetSuggestion($suggestionid) ;
+$xml=$data->{xml};
+$xmlhash=XML_xml2hash_onerecord($xml);
+}
 my $encoding="";
 ($xmlhash,$encoding) = MARCfindbreeding($dbh,$breedingid,$oldbiblionumber) if ($breedingid);
 
index 453a062..b2f9c2d 100755 (executable)
@@ -37,6 +37,7 @@ my $showoffset = $offset + 1;
 my $total;
 my $count;
 my @results;
+my $facets;
 my %search;
 my $toggle;
 my $marc_p = C4::Context->boolean_preference("marc");
@@ -66,7 +67,7 @@ my @kohafield;
 my @value;
 my @relation;
 my @and_or;
-my $order="title";
+my $order="title,1";
 if ($isbn){
 $search{'isbn'}=$isbn;
 push @kohafield, "isbn";
@@ -81,7 +82,7 @@ $search{avoidquerylog}=1;
 if ($SQLorZEBRA eq "sql"){
 ($count, @results) =cataloguing_search(\%search,$num,$offset);
 }else{
-($count,@results) =ZEBRAsearch_kohafields(\@kohafield,\@value, \@relation,$order, \@and_or, 1,"",$offset, $num,"intranet");
+($count,$facets,@results) =ZEBRAsearch_kohafields(\@kohafield,\@value, \@relation,$order, \@and_or, 1,"",$offset, $num,"intranet");
 
 }
 my $grandtotal=$count;
index 418b5f0..f5d86fe 100644 (file)
 use strict;
 use CGI;
 use C4::Circulation::Circ3;
-#use C4::Search;
-use C4::Output;
-use C4::Print;
-use DBI;
 use C4::Auth;
 use C4::Interface::CGI::Output;
 use C4::Koha;
-#use HTML::Template;
 use C4::Date;
 use C4::Context;
 use C4::Members;
+use C4::Print;
 #
 # PARAMETERS READING
 #
@@ -50,9 +46,8 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user
        authnotrequired => 0,
        flagsrequired   => { circulate => 1 },
     });
-my $branches = getbranches();
+my $branches = GetBranches();
 my $printers = getprinters();
-#my $branch = getbranch($query, $branches);
 my $branch=C4::Context->preference("defaultBranch");
 my $printer = getprinter($query, $printers);
 
index 13a7341..9f1d1dc 100755 (executable)
--- a/logout.pl
+++ b/logout.pl
@@ -69,7 +69,7 @@ my $cookie=$query->cookie(-name => 'sessionID',
 
 # Should redirect to intranet home page after logging out
 
-print $query->redirect("userpage.pl");
+print $query->redirect("mainpage.pl");
 exit;
 
 
index a2d845f..dd8c465 100755 (executable)
@@ -1,25 +1,14 @@
-#!/usr/bin/perl
-use HTML::Template;
+#!/usr/bin/perl 
 use strict;
-require Exporter;
-use C4::Database;
-use C4::Output;  # contains gettemplate
 use C4::Interface::CGI::Output;
 use CGI;
 use C4::Auth;
-use C4::AuthoritiesMarc;
+use C4::Suggestions;
 use C4::Koha;
+use C4::BookShelves;
 use C4::NewsChannels;
-my $query = new CGI;
-my $authtypes = getauthtypes;
-my @authtypesloop;
-foreach my $thisauthtype (sort { $authtypes->{$a} <=> $authtypes->{$b} } keys %$authtypes) {
-       my %row =(value => $thisauthtype,
-                               authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
-                       );
-       push @authtypesloop, \%row;
-}
 
+my $query = new CGI;
 my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "intranet-main.tmpl",
                             query => $query,
@@ -28,17 +17,25 @@ my ($template, $loggedinuser, $cookie)
                             flagsrequired => {catalogue => 1, circulate => 1,
                                                        parameters => 1, borrowers => 1,
                                                        permissions =>1, reserveforothers=>1,
-                                                       borrow => 1, reserveforself => 1,
                                                        editcatalogue => 1, updatecharges => 1, },
                             debug => 1,
                             });
 
+my $lang = "koha";
+my $error=$query->param('error');
+$template->param(error        =>$error);
+my ($opac_news_count, $all_opac_news) = &get_opac_news(undef, $lang);
+# if ($opac_news_count > 4) {$template->param(more_opac_news => 1);}
+$template->param(opac_news        => $all_opac_news);
+$template->param(opac_news_count  => $opac_news_count);
+
 my $marc_p = C4::Context->boolean_preference("marc");
 $template->param(NOTMARC => !$marc_p);
-$template->param(authtypesloop => \@authtypesloop);
+my $new_suggestions = &CountSuggestion("ASKED");
+$template->param(new_suggestions => $new_suggestions);
+
 
-my ($koha_news_count, $all_koha_news) = &get_opac_news(undef, 'koha');
-$template->param(koha_news        => $all_koha_news);
-$template->param(koha_news_count  => $koha_news_count);
+my $count_pending_request = CountShelfRequest(undef, "PENDING");
+$template->param(count_pending_request => $count_pending_request);
+output_html_with_http_headers $query, $cookie, $template->output();
 
-output_html_with_http_headers $query, $cookie, $template->output;
index b5a4334..82ac243 100755 (executable)
@@ -29,11 +29,14 @@ use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Date;
 use CGI;
-use C4::Search;
 use C4::Members;
+use HTML::Template;
+
 my $input=new CGI;
 
 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
+#my %tmpldata = pathtotemplate ( template => 'boraccount.tmpl', theme => $theme );
+#my $template = HTML::Template->new(filename => $tmpldata{'path'}, die_on_bad_params => 0);
 my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "members/boraccount.tmpl",
                             query => $input,
@@ -74,16 +77,13 @@ for (my $i=0;$i<$numaccts;$i++){
        $accts->[$i]{'amountoutstandingcredit'} = 1;
   }
   my %row = (   'date'              => format_date($accts->[$i]{'date'}),
-               'accountid' => $accts->[$i]{'accountid'},
-               'itemnum' => $accts->[$i]{'itemnumber'},
                'amountcredit' => $accts->[$i]{'amountcredit'},
                'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
                'toggle' => $accts->[$i]{'toggle'},
                'description'       => $accts->[$i]{'description'},
                'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
-               'accounttype'   =>$accts->[$i]{'accounttype'},
                'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}) );
-               
+
   if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
     $row{'printtitle'}=1;
     $row{'title'} = $accts->[$i]{'title'};
index 4ef5aa1..bb508ba 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-#wrriten 18/09/2005 by TG
+#wrriten 11/1/2000 by chris@katipo.oc.nz
 #script to display borrowers account details
 
 
@@ -26,60 +26,37 @@ use C4::Auth;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-
-use C4::Search;
-use C4::Accounts2;
+use HTML::Template;
 use C4::Members;
+use C4::Accounts2;
 my $input=new CGI;
-  my $accounttype=$input->param('accounttype');
- my $accountid=$input->param('accountid');
-my $amount=$input->param('amount');
-my $itemnum=$input->param('itemnum');
-my $error=0;
+
+
 my $bornum=$input->param('bornum');
 #get borrower details
 my $data=borrdata('',$bornum);
-my $user=$data->{firstname}.",".$data->{surname}."-".$data->{cardnumber};
 my $add=$input->param('add');
-# $error=$input->param('error');
-my ($template, $loggedinuser, $cookie)
-       = get_template_and_user({template_name => "members/mancredit.tmpl",
+if ($add){
+  my $itemnum=$input->param('itemnum');
+  my $desc=$input->param('desc');
+  my $amount=$input->param('amount');
+  $amount = -$amount;
+  my $type=$input->param('type');
+  manualinvoice($bornum,$itemnum,$desc,$type,$amount);
+  print $input->redirect("/cgi-bin/koha/members/boraccount.pl?bornum=$bornum");
+} else {
+       my ($template, $loggedinuser, $cookie)
+       = get_template_and_user({template_name => "mancredit.tmpl",
                                        query => $input,
                                        type => "intranet",
                                        authnotrequired => 0,
                                        flagsrequired => {borrowers => 1},
                                        debug => 1,
                                        });
-       $template->param(user => $user);
-       $template->param( bornum => $bornum);
-       $template->param( itemnum => $itemnum);
-       $template->param( amount => $amount);
-       $template->param( accounttype => $accounttype);
-       $template->param( accountid => $accountid);
-if ($add){
-if ($accounttype eq "F" || $accounttype eq "FU"){
-$accounttype="CF";
-}else{
-$accounttype="C".$accounttype;
-}
-       
-  my $desc=$input->param('desc');
-  my $amount=$input->param('amount');
-  $amount = -$amount;
-my $loggeduser=$input->param('loggedinuser');
-my   $error=manualcredit($bornum,$accountid,$desc,$accounttype,$amount,$loggeduser);
-       if ($error>0 ) {
-       $template->param( error => "1");
-       $template->param(user => $user);
        $template->param( bornum => $bornum);
-       $template->param( itemnum => $itemnum);
-       $template->param( amount => $amount);
-       $template->param( accounttype => $accounttype);
-       $template->param( accountid => $accountid);
-       } else {
-       print $input->redirect("/cgi-bin/koha/members/boraccount.pl?bornum=$bornum");
-       }
-} 
-       
+       print $input->header(
+           -type => guesstype($template->output),
+           -cookie => $cookie
+       ),$template->output;
 
-output_html_with_http_headers $input, $cookie, $template->output;
+}
index 9dc43ac..bb265c8 100755 (executable)
@@ -26,28 +26,27 @@ use C4::Auth;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
-use C4::Accounts2;
 use C4::Members;
-
+use C4::Accounts2;
+use HTML::Template;
 
 my $input=new CGI;
 
 my $bornum=$input->param('bornum');
 #get borrower details
 my $data=borrdata('',$bornum);
-my $user=$data->{firstname}.",".$data->{surname}."-".$data->{cardnumber};
 my $add=$input->param('add');
 if ($add){
 #  print $input->header;
+  my $itemnum=$input->param('itemnum');
   my $desc=$input->param('desc');
   my $amount=$input->param('amount');
   my $type=$input->param('type');
-  manualinvoice($bornum,$desc,$type,$amount);
+  manualinvoice($bornum,$itemnum,$desc,$type,$amount);
   print $input->redirect("/cgi-bin/koha/members/boraccount.pl?bornum=$bornum");
 } else {
        my ($template, $loggedinuser, $cookie)
-       = get_template_and_user({template_name => "members/maninvoice.tmpl",
+       = get_template_and_user({template_name => "maninvoice.tmpl",
                                        query => $input,
                                        type => "intranet",
                                        authnotrequired => 0,
@@ -55,6 +54,9 @@ if ($add){
                                        debug => 1,
                                        });
        $template->param(bornum => $bornum);
-       $template->param(user => $user);
-       output_html_with_http_headers $input, $cookie, $template->output;
+       print $input->header(
+           -type => guesstype($template->output),
+           -cookie => $cookie
+       ),$template->output;
+
 }
index ca34e0d..9b1b7d5 100755 (executable)
@@ -24,14 +24,12 @@ use strict;
 # external modules
 use Date::Calc qw/Today/;
 use CGI;
-use HTML::Template;
 use Date::Manip;
 use Digest::MD5 qw(md5_base64);
 
 # internal modules
 use C4::Auth;
 use C4::Context;
-use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Search;
 use C4::Members;
index ab9b544..e98d24f 100755 (executable)
@@ -185,7 +185,7 @@ for (my $i=0;$i<$count;$i++){
        #check item is not reserved
        my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
        if ($restype){
-#              print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
+#              print "<TD><a href=/cgi-bin/koha/reserve/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
                #  } elsif ($issue->[$i]->{'renewals'} > 0) {
                #      print "<TD>Previously Renewed - no renewals</td></tr>";
                        $row{'norenew'}=1;
index 11305be..2b4c442 100755 (executable)
@@ -1,11 +1,9 @@
 #!/usr/bin/perl
-# WARNING: Not enough context to figure out the correct tabstop size
-# WARNING: Assume that this file uses 4-character tabs
 
 # $Id$
 
-#written 11/1/2000 by chris@katipo.oc.nz
-#part of the koha library system, script to facilitate paying off fines
+# written 11/1/2000 by chris@katipo.oc.nz
+# part of the koha library system, script to facilitate paying off fines
 
 
 # Copyright 2000-2002 Katipo Communications
 use strict;
 use C4::Context;
 use C4::Auth;
-use C4::Interface::CGI::Output;
+use C4::Output;
 use CGI;
-use C4::Search;
+use C4::Members;
 use C4::Accounts2;
 use C4::Stats;
-use C4::Members;
+use C4::Koha;
+use HTML::Template;
 
 my $input=new CGI;
-my ($template, $loggedinuser, $cookie)
-               = get_template_and_user ({ template_name => "members/pay.tmpl",
-                                          query => $input,
-                                          type => "intranet",
-                                          authnotrequired => 0,
-                                          flagsrequired => {borrowers => 1},
-                                          debug => 1,
-                                        });
 
+#print $input->header;
 my $bornum=$input->param('bornum');
 if ($bornum eq ''){
        $bornum=$input->param('bornum0');
 }
-#get borrower details
+# get borrower details
 my $data=borrdata('',$bornum);
-my $user=C4::Context->preference('defaultBranch');
-my $me=borrdata('',$loggedinuser);
-my $accountant=$me->{'firstname'}.' '.$me->{'surname'};
-#get account details
+my $user=$input->remote_user;
+
+# get account details
 my %bor;
 $bor{'borrowernumber'}=$bornum;
+my $branches = GetBranches();
+my $printers = getprinters();
+my $branch = getbranch($input, $branches);
 
 my @names=$input->param;
 my %inp;
 my $check=0;
-my $type;
-my $totalamount;
-my $totaldesc;
-my $totalaccounttype;
-
 for (my $i=0;$i<@names;$i++){
-       my$temp=$input->param($names[$i]);
+       my $temp=$input->param($names[$i]);
        if ($temp eq 'wo'){
-               $type="W";
-               $check=2;
+               $inp{$names[$i]}=$temp;
+               $check=1;
        }
-if ($temp eq 'yes'){
-               $type="Pay";
-               $check=2;
-       }
-       if ($temp eq 'yes' || $temp eq 'wo'){
-               
-               my $desc=$input->param($names[$i+7]);
-               my $accounttype=$input->param($names[$i+2]);
+       if ($temp eq 'yes'){
+               # For HLT
+               $user=~ s/Levin/L/i;
+               $user=~ s/Foxton/F/i;
+               $user=~ s/Shannon/S/i;
+               # FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
                my $amount=$input->param($names[$i+4]);
                my $bornum=$input->param($names[$i+5]);
                my $accountno=$input->param($names[$i+6]);
-               my $amounttopay=$input->param($names[$i+8]);
-
-               makepayment($bornum,$accountno,$amounttopay,$accountant, $type);
-               $totalamount=$totalamount+$amounttopay;
-               $totaldesc .="<br> ".$desc."-  Fee:".$amounttopay;
-               $totalaccounttype .="<br> ".$accounttype;
+               makepayment($bornum,$accountno,$amount,$user,$branch);
                $check=2;
        }
 }
-if ($type eq "Pay" || $type eq "W"){
-print $input->redirect("/cgi-bin/koha/members/payprint.pl?bornum=$bornum&accounttype=$totalaccounttype&amount=$totalamount&desc=$totaldesc");
-}
 my %env;
-   
+    $user=~ s/Levin/L/i;
+    $user=~ s/Foxton/F/i;
+    $user=~ s/Shannon/S/i;
 
-$env{'branchcode'}=C4::Context->preference('defaultBranch');
+$env{'branchcode'}=$branch;
 my $total=$input->param('total');
 if ($check ==0){
-       
+       my($template, $loggedinuser, $cookie)
+               = get_template_and_user ({ template_name => "members/pay.tmpl",
+                                          query => $input,
+                                          type => "intranet",
+                                          authnotrequired => 0,
+                                          flagsrequired => {borrowers => 1},
+                                          debug => 1,
+                                        });
        if ($total ne ''){
                recordpayment(\%env,$bornum,$total);
        }
@@ -129,11 +117,12 @@ if ($check ==0){
                                                        surname => $data->{'surname'},
                                                        bornum => $bornum,
                                                        loop_pay => \@loop_pay,
-                                                       total => sprintf("%.2f",$total),
-                                                       totalamountopay => sprintf("%.2f",$total));
-output_html_with_http_headers $input, $cookie, $template->output;
+                                                       total => sprintf("%.2f",$total));
+       print "Content-Type: text/html\n\n", $template->output;
 
 } else {
+#  my $quety=$input->query_string;
+#  print $input->redirect("/cgi-bin/koha/sec/writeoff.pl?$quety");
        my%inp;
        my @name=$input->param;
        for (my $i=0;$i<@name;$i++){
@@ -151,14 +140,33 @@ output_html_with_http_headers $input, $cookie, $template->output;
                $bornum=$input->param("bornum$value");
                my $itemno=$input->param("itemnumber$value");
                my $amount=$input->param("amount$value");
-               
+               my $accountno=$input->param("accountno$value");
+               writeoff($bornum,$accountno,$itemno,$accounttype,$amount);
        }
        $bornum=$input->param('bornum');
-       print $input->redirect("/cgi-bin/koha/members/pay.pl?bornum=$bornum");
+       print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$bornum");
 }
 
 
-
+sub writeoff{
+       my ($bornum,$accountnum,$itemnum,$accounttype,$amount)=@_;
+       my $user=$input->remote_user;
+       my $dbh = C4::Context->dbh;
+       my $env;
+       my $sth=$dbh->prepare("Update accountlines set amountoutstanding=0 where accounttype='Res' and accountno=? and borrowernumber=?");
+        $sth->execute($accountnum,$bornum);
+       $sth->finish;
+       $sth=$dbh->prepare("select max(accountno) from accountlines");
+       $sth->execute;
+       my $account=$sth->fetchrow_hashref;
+       $sth->finish;
+       $account->{'max(accountno)'}++;
+       $sth=$dbh->prepare("insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
+                                               values (?,?,?,now(),?,'Writeoff','W')");
+       $sth->execute($bornum,$account->{'max(accountno)'},$itemnum,$amount);
+       $sth->finish;
+       UpdateStats($env,$branch,'writeoff',$amount,'','','',$bornum);
+}
 
 # Local Variables:
 # tab-width: 4
index ed5e976..14eb66c 100755 (executable)
@@ -4,11 +4,9 @@ use strict;
 use CGI;
 
 use C4::Auth;
-use C4::Output;
+
 use C4::Interface::CGI::Output;
-use C4::Database;
-use HTML::Template;
-use C4::Calendar;
+use C4::Calendar::Calendar;
 
 my $input = new CGI;
 my $dbh = C4::Context->dbh();
@@ -21,7 +19,7 @@ my $year = $input->param('showYear');
 my $title = $input->param('showTitle');
 my $description = $input->param('showDescription');
 
-my $calendar = C4::Calendar->new(branchcode => $branchcode);
+my $calendar = C4::Calendar::Calendar->new(branchcode => $branchcode);
 
 if ($input->param('showOperation') eq 'exception') {
        $calendar->insert_exception_holiday(day => $day,
index e8561d8..c2c03a3 100755 (executable)
@@ -11,7 +11,7 @@ use C4::Calendar::Calendar;
 
 my $input = new CGI;
 my $branch = $input->param('branch');
-my $branch=C4::Context->preference('defaultbranch') unless $branch;
+$branch=C4::Context->preference('defaultBranch') unless $branch;
 my $dbh = C4::Context->dbh();
 
 # Set all the branches.
@@ -26,14 +26,13 @@ my @listValues = keys(%list);
 if (!defined($branch)) {
        $branch =$listValues[4];
 }
-my $branchesList = CGI::scrolling_list(-name => 'branch',
+my $branchesList = CGI::scrolling_list(-name => 'branch', -id=>'branch',
                                               -values => \@listValues,
                                                   -labels => \%list,
                                                   -size => 1,
-                                                                          -default => [$branch],
+                                        -default => [$branch],
                                                   -multiple => 0,
-                                                                          -id => "branch",
-                                                                          -onChange => "changeBranch()");
+                                        -onChange => "changeBranch()");
 
 $branches->finish;
 
index 1f4f66d..de971a0 100755 (executable)
@@ -95,8 +95,8 @@ my $file;
 #---------------
 # log cleared, as marcimport is (almost) rewritten from scratch.
 # $Log$
-# Revision 1.2  2006/09/11 17:41:56  tgarip1957
-# New XML API
+# Revision 1.3  2006/09/27 21:19:22  tgarip1957
+# Finalized XML version for intranet
 #
 # Revision 1.2.4.1  2005/04/07 10:10:52  tipaul
 # copying processz3950queue from 2.0 branch. The 2.2 version misses an important fix
index e36ab5c..5dba03e 100755 (executable)
@@ -27,7 +27,6 @@ use CGI;
 use C4::Context;
 use C4::Output;
 use C4::Auth;
-use HTML::Template;
 use PDF::API2;
 use PDF::API2::Page;
 use PDF::API2::PDF::Utils;
index 4b9e680..d4a421a 100755 (executable)
@@ -3,10 +3,8 @@
 use strict;
 use CGI;
 use C4::Auth;
-use C4::Output;
 use C4::Interface::CGI::Output;
-use C4::Database;
-use HTML::Template;
+
 
 my $query = new CGI;
 my ($template, $loggedinuser, $cookie)