- }
-}
-elsif ( $op eq 'delete' ) {
- # if the user has pressed the "delete branch" button.
-
- # check to see if the branchcode is being used in the database somewhere....
- my $dbh = C4::Context->dbh;
- my $sthitems = $dbh->prepare("select count(*) from items where holdingbranch=? or homebranch=?");
- my $sthborrowers = $dbh->prepare("select count(*) from borrowers where branchcode=?");
- $sthitems->execute( $branchcode, $branchcode );
- $sthborrowers->execute( $branchcode );
- my ($totalitems) = $sthitems->fetchrow_array;
- my ($totalborrowers) = $sthborrowers->fetchrow_array;
- if ($totalitems && !$totalborrowers) {
- $template->param( else => 1 );
- default("MESSAGE10", $template);
- }
- elsif (!$totalitems && $totalborrowers){
- $template->param( else => 1 );
- default("MESSAGE11", $template);
- }
- elsif ($totalitems && $totalborrowers){
- $template->param( else => 1 );
- default("MESSAGE7", $template);
- }
- else {
- $template->param( delete_confirm => 1 );
- $template->param( branchname => $branchname );
- $template->param( branchcode => $branchcode );
- }
-}
-elsif ( $op eq 'delete_confirmed' ) {
-
- # actually delete branch and return to the main screen....
- DelBranch($branchcode);
- $template->param( else => 1 );
- default("MESSAGE3",$template);
-}
-elsif ( $op eq 'editcategory' ) {
-
- # If the user has pressed the "add new category" or "modify" buttons.
- $template->param( 'heading_branches_edit_category_p' => 1 );
- editcatform($categorycode,$template);
-}
-elsif ( $op eq 'addcategory_validate' ) {
-
- $template->param( else => 1 );
- # confirm settings change...
- my $params = $input->Vars;
- unless ( $params->{'categorycode'} && $params->{'categoryname'} ) {
- default("MESSAGE4",$template);
- }
- elsif ($input->param('add')){
- # doing an add must check the code is unique
- if (CheckCategoryUnique($input->param('categorycode'))){
- ModBranchCategoryInfo($params);
- default("MESSAGE5",$template);
- }
- else {
- default("MESSAGE9",$template);
- }
- }
- else {
- ModBranchCategoryInfo($params);
- default("MESSAGE5",$template);
- }
-}
-elsif ( $op eq 'delete_category' ) {
-
- # if the user has pressed the "delete branch" button.
- if ( CheckBranchCategorycode($categorycode) ) {
- $template->param( else => 1 );
- default( 'MESSAGE8', $template );
- } else {
- $template->param( delete_category => 1 );
- $template->param( categorycode => $categorycode );
- }
-}
-elsif ( $op eq 'categorydelete_confirmed' ) {
-
- # actually delete branch and return to the main screen....
- DelBranchCategory($categorycode);
- $template->param( else => 1 );
- default("MESSAGE6",$template);
-
-}
-else {
- # if no operation has been set...
- default("",$template);
-}
-
-################################################################################
-#
-# html output functions....
-
-sub default {
- my $message = shift || '';
- my $innertemplate = shift or return;
- $innertemplate->param($message => 1) if $message;
- $innertemplate->param(
- 'heading_branches_p' => 1,
- );
- branchinfotable("",$innertemplate);
-}
-
-sub editbranchform {
- my ($branchcode,$innertemplate) = @_;
- # initiate the scrolling-list to select the printers
- my $printers = GetPrinters();
- my @printerloop;
- my $data;
- my $oldprinter = "";
-
- if ($branchcode) {
- $data = GetBranchInfo($branchcode);
- $data = $data->[0];
-
- # get the old printer of the branch
- $oldprinter = $data->{'branchprinter'} || '';
- _branch_to_template($data, $innertemplate);
- }