Changing table row color toggle so that color values can be specified in the template...
[koha-ffzg.git] / admin / itemtypes.pl
index 44286d5..64fe84a 100755 (executable)
@@ -96,14 +96,13 @@ if ($op eq 'add_form') {
        my $data;
        if ($itemtype) {
                my $dbh = C4::Context->dbh;
-               my $sth=$dbh->prepare("select itemtype,description,loanlength,renewalsallowed,rentalcharge,notforloan from itemtypes where itemtype=?");
+               my $sth=$dbh->prepare("select itemtype,description,renewalsallowed,rentalcharge,notforloan from itemtypes where itemtype=?");
                $sth->execute($itemtype);
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        }
        $template->param(itemtype => $itemtype,
                                                        description => $data->{'description'},
-                                                       loanlength => $data->{'loanlength'},
                                                        renewalsallowed => $data->{'renewalsallowed'},
                                                        rentalcharge => $data->{'rentalcharge'},
                                                        notforloan => $data->{'notforloan'}
@@ -114,23 +113,11 @@ if ($op eq 'add_form') {
 # called by add_form, used to insert/modify data in DB
 } elsif ($op eq 'add_validate') {
        my $dbh = C4::Context->dbh;
-       my $query = "replace itemtypes (itemtype,description,loanlength,renewalsallowed,rentalcharge,notforloan) values (";
-       $query.= $dbh->quote($input->param('itemtype')).",";
-       $query.= $dbh->quote($input->param('description')).",";
-       $query.= $dbh->quote($input->param('loanlength')).",";
-       if ($input->param('renewalsallowed') ne 1) {
-               $query.= "0,";
-       } else {
-               $query.= "1,";
-       }
-       $query.= $dbh->quote($input->param('rentalcharge')).",";
-       if ($input->param('notforloan') ne 1) {
-               $query.= "0)";
-       } else {
-               $query.= "1)";
-       }
-       my $sth=$dbh->prepare($query);
-       $sth->execute;
+       my $sth=$dbh->prepare("replace itemtypes (itemtype,description,renewalsallowed,rentalcharge,notforloan) values (?,?,?,?,?)");
+       $sth->execute(
+               $input->param('itemtype'),$input->param('description'),
+               $input->param('renewalsallowed'),$input->param('rentalcharge'),
+               $input->param('notforloan')?1:0);
        $sth->finish;
        print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypes.pl\"></html>";
        exit;
@@ -143,21 +130,20 @@ if ($op eq 'add_form') {
 
        # Check both categoryitem and biblioitems, see Bug 199
        my $total = 0;
-       for my $table ('issuingrules', 'biblioitems') {
+       for my $table ('biblioitems') {
           my $sth=$dbh->prepare("select count(*) as total from $table where itemtype=?");
           $sth->execute($itemtype);
           $total += $sth->fetchrow_hashref->{total};
           $sth->finish;
        }
 
-       my $sth=$dbh->prepare("select itemtype,description,loanlength,renewalsallowed,rentalcharge from itemtypes where itemtype=?");
+       my $sth=$dbh->prepare("select itemtype,description,renewalsallowed,rentalcharge from itemtypes where itemtype=?");
        $sth->execute($itemtype);
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
 
        $template->param(itemtype => $itemtype,
                                                        description => $data->{'description'},
-                                                       loanlength => $data->{'loanlength'},
                                                        renewalsallowed => $data->{'renewalsallowed'},
                                                        rentalcharge => $data->{'rentalcharge'},
                                                        total => $total);
@@ -170,6 +156,8 @@ if ($op eq 'add_form') {
        my $itemtype=uc($input->param('itemtype'));
        my $sth=$dbh->prepare("delete from itemtypes where itemtype=?");
        $sth->execute($itemtype);
+       $sth = $dbh->prepare("delete from issuingrules where itemtype=?");
+       $sth->execute($itemtype);
        $sth->finish;
        print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=itemtypes.pl\"></html>";
        exit;
@@ -189,7 +177,6 @@ if ($op eq 'add_form') {
                }
                $row_data{itemtype} = $results->[$i]{'itemtype'};
                $row_data{description} = $results->[$i]{'description'};
-               $row_data{loanlength} = $results->[$i]{'loanlength'};
                $row_data{renewalsallowed} = $results->[$i]{'renewalsallowed'};
                $row_data{rentalcharge} = $results->[$i]{'rentalcharge'};
                push(@loop_data, \%row_data);