3 #script to administer the contract table
4 #written 02/09/2008 by john.soros@biblibre.com
6 # Copyright 2008-2009 BibLibre SARL
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 use C4
::Dates qw
/format_date format_date_in_iso/;
30 use C4
::Bookseller qw
/GetBookSellerFromId/;
34 my $contractnumber = $input->param('contractnumber');
35 my $booksellerid = $input->param('booksellerid');
36 my $op = $input->param('op') || '';
38 my $bookseller = GetBookSellerFromId
($booksellerid);
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
41 { template_name
=> "admin/aqcontract.tmpl",
45 flagsrequired
=> { acquisition
=> 'contracts_manage' },
51 contractnumber
=> $contractnumber,
52 booksellerid
=> $booksellerid,
53 booksellername
=> $bookseller->{name
},
54 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
55 dateformat
=> C4
::Context
->preference("dateformat"),
58 #ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record
59 if ( $op eq 'add_form' ) {
60 $template->param( add_form
=> 1 );
62 # if contractnumber exists, it's a modify action, so read values to modify...
63 my $contract = @
{GetContract
( { contractnumber
=> $contractnumber } )}[0] if $contractnumber;
66 contractnumber
=> $$contract{contractnumber
},
67 contractname
=> $$contract{contractname
},
68 contractdescription
=> $$contract{contractdescription
},
69 contractstartdate
=> format_date
( $$contract{contractstartdate
} ),
70 contractenddate
=> format_date
( $$contract{contractenddate
} ),
71 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar,
76 #ADD_VALIDATE: called by add_form, used to insert/modify data in DB
77 elsif ( $op eq 'add_validate' ) {
78 ## Please see file perltidy.ERR
79 $template->param( add_validate
=> 1 );
81 my $is_a_modif = $input->param("is_a_modif");
85 contractstartdate
=> format_date_in_iso
( $input->param('contractstartdate') ),
86 contractenddate
=> format_date_in_iso
( $input->param('contractenddate') ),
87 contractname
=> $input->param('contractname'),
88 contractdescription
=> $input->param('contractdescription'),
89 booksellerid
=> $input->param('booksellerid'),
90 contractnumber
=> $input->param('contractnumber'),
94 contractname
=> $input->param('contractname'),
95 contractdescription
=> $input->param('contractdescription'),
96 booksellerid
=> $input->param('booksellerid'),
97 contractstartdate
=> format_date_in_iso
( $input->param('contractstartdate') ),
98 contractenddate
=> format_date_in_iso
( $input->param('contractenddate') ),
102 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?supplierid=$booksellerid");
105 # END $OP eq ADD_VALIDATE
107 #DELETE_CONFIRM: called by default form, used to confirm deletion of data in DB
108 elsif ( $op eq 'delete_confirm' ) {
109 $template->param( delete_confirm
=> 1 );
111 my $contract = @
{GetContract
( { contractnumber
=> $contractnumber } )}[0];
114 contractnumber
=> $$contract{contractnumber
},
115 contractname
=> $$contract{contractname
},
116 contractdescription
=> $$contract{contractdescription
},
117 contractstartdate
=> format_date
( $$contract{contractstartdate
} ),
118 contractenddate
=> format_date
( $$contract{contractenddate
} ),
121 # END $OP eq DELETE_CONFIRM
123 #DELETE_CONFIRMED: called by delete_confirm, used to effectively confirm deletion of data in DB
124 elsif ( $op eq 'delete_confirmed' ) {
125 $template->param( delete_confirmed
=> 1 );
127 DelContract
( { contractnumber
=> $contractnumber } );
129 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?supplierid=$booksellerid");
132 # END $OP eq DELETE_CONFIRMED
134 # DEFAULT: Builds a list of contracts and displays them
136 $template->param(else => 1);
139 my @contracts = @
{GetContract
( { booksellerid
=> $booksellerid } )};
143 $$_{contractstartdate
} = format_date
($$_{contractstartdate
});
144 $$_{contractenddate
} = format_date
($$_{contractenddate
});
147 $template->param(loop => \
@contracts);
149 #---- END $OP eq DEFAULT
152 output_html_with_http_headers
$input, $cookie, $template->output;