From: Paul Poulain <[email protected]> --- admin/aqcontract.pl | 223 ++++++++++++++++++ .../prog/en/modules/admin/aqcontract.tmpl | 248 ++++++++++++++++++++ 2 files changed, 471 insertions(+), 0 deletions(-) create mode 100755 admin/aqcontract.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl
diff --git a/admin/aqcontract.pl b/admin/aqcontract.pl new file mode 100755 index 0000000..37a7600 --- /dev/null +++ b/admin/aqcontract.pl @@ -0,0 +1,223 @@ +#!/usr/bin/perl + +#script to administer the contract table +#written 02/09/2008 by [email protected] + +# Copyright 2008-2009 BibLibre SARL +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use warnings; +use CGI; +use C4::Context; +use C4::Auth; +use C4::Output; +use C4::Dates qw/format_date format_date_in_iso/; +use C4::Bookseller qw/GetBookSeller/; + +sub StringSearch { + my ($searchstring)=...@_; + my $dbh = C4::Context->dbh; + $searchstring=~ s/\'/\\\'/g; + my @data=split(' ',$searchstring); + my $sth=$dbh->prepare("Select * from aqcontract where (contractdescription like ? or contractname like ?) order by contractnumber"); + $sth->execute("%$data[0]%","%$data[0]%"); + my @results; + while (my $row=$sth->fetchrow_hashref){ + push(@results,$row); + } + $sth->finish; + return (scalar(@results),\...@results); +} + +my $input = new CGI; +my $searchfield = $input->param('searchfield'); +my $script_name = "/cgi-bin/koha/admin/aqcontract.pl"; +my $contractnumber = $input->param('contractnumber'); +my $op = $input->param('op'); + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "admin/aqcontract.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { acquisition => 'contracts_manage' }, + debug => 1, + } +); + +$template->param( + script_name => $script_name, + contractnumber => $contractnumber, + searchfield => $searchfield +); + + +#ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record +if ( $op eq 'add_form' ) { + $template->param( add_form => 1 ); + my $data; + my @booksellerloop = GetBookSeller(""); + + #---- if primkey exists, it's a modify action, so read values to modify... + if ($contractnumber) { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select * from aqcontract where contractnumber=?"); + $sth->execute($contractnumber); + $data = $sth->fetchrow_hashref; + $sth->finish; + + for my $bookseller (@booksellerloop) { + if ( $bookseller->{'id'} eq $data->{'booksellerid'} ) { + $bookseller->{'selected'} = 1; + } + } + } + $template->param( + contractnumber => $data->{'contractnumber'}, + contractname => $data->{'contractname'}, + contractdescription => $data->{'contractdescription'}, + contractstartdate => format_date( $data->{'contractstartdate'} ), + contractenddate => format_date( $data->{'contractenddate'} ), + booksellerloop => \...@booksellerloop, + booksellerid => $data->{'booksellerid'}, + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), + ); + + # END $OP eq ADD_FORM + + #ADD_VALIDATE: called by add_form, used to insert/modify data in DB +} +elsif ( $op eq 'add_validate' ) { +## Please see file perltidy.ERR + $template->param( add_validate => 1 ); + my $is_a_modif = $input->param("is_a_modif"); + my $dbh = C4::Context->dbh; + if ($is_a_modif) { + my $sth = $dbh->prepare( + "UPDATE aqcontract SET contractstartdate=?, + contractenddate=?, + contractname=?, + contractdescription=?, + booksellerid=? WHERE contractnumber=?" + ); + $sth->execute( + format_date_in_iso( $input->param('contractstartdate') ), + format_date_in_iso( $input->param('contractenddate') ), + $input->param('contractname'), + $input->param('contractdescription'), + $input->param('booksellerid'), + $input->param('contractnumber') + ); + $sth->finish; + } else { + my $sth = $dbh->prepare("INSERT INTO aqcontract (contractname,contractdescription,booksellerid,contractstartdate,contractenddate) values (?, ?, ?, ?, ?)"); + $sth->execute( + $input->param('contractname'), + $input->param('contractdescription'), + $input->param('booksellerid'), + format_date_in_iso( $input->param('contractstartdate') ), + format_date_in_iso( $input->param('contractenddate') ) + ); + $sth->finish; + } + print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=aqcontract.pl\"></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' ) { + $template->param( delete_confirm => 1 ); + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select contractnumber,contractstartdate,contractenddate, + contractname,contractdescription,booksellerid + from aqcontract where contractnumber=?"); + $sth->execute($contractnumber); + my $data = $sth->fetchrow_hashref; + $sth->finish; + + my $query = "SELECT name FROM aqbooksellers WHERE id LIKE $data->{'booksellerid'}"; + my $sth2 = $dbh->prepare($query); + $sth2->execute; + my $result = $sth2->fetchrow; + my $booksellername = $result; + + $template->param( + contractnumber => $data->{'contractnumber'}, + contractname => $data->{'contractname'}, + contractdescription => $data->{'contractdescription'}, + contractstartdate => format_date( $data->{'contractstartdate'} ), + contractenddate => format_date( $data->{'contractenddate'} ), + booksellerid => $data->{'booksellerid'}, + booksellername => $booksellername, + ); + + # 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' ) { + $template->param( delete_confirmed => 1 ); + my $dbh = C4::Context->dbh; + my $contractnumber = $input->param('contractnumber'); + my $sth = $dbh->prepare("delete from aqcontract where contractnumber=?"); + $sth->execute($contractnumber); + $sth->finish; + print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=aqcontract.pl\"></html>"; + exit; + + # END $OP eq DELETE_CONFIRMED + # DEFAULT: Builds a list of contracts and displays them +} else { + $template->param(else => 1); + my @loop; + my ($count,$results)=StringSearch($searchfield); + my $toggle = 0; + for (my $i=0; $i < $count; $i++){ + if ( ($input->param('booksellerid') && $results->[$i]{'booksellerid'} == $input->param('booksellerid')) || ! $input->param('booksellerid') ) { + my %row = (contractnumber => $results->[$i]{'contractnumber'}, + contractname => $results->[$i]{'contractname'}, + contractdescription => $results->[$i]{'contractdescription'}, + contractstartdate => format_date($results->[$i]{'contractstartdate'}), + contractenddate => format_date($results->[$i]{'contractenddate'}), + booksellerid => $results->[$i]{'booksellerid'}, + toggle => $toggle ); + push @loop, \%row; + if ( $toggle eq 0 ) + { + $toggle = 1; + } + else + { + $toggle = 0; + } + } + } + for my $contract (@loop) { + my $dbh = C4::Context->dbh; + my $query = "SELECT name FROM aqbooksellers WHERE id LIKE $contract->{'booksellerid'}"; + my $sth =$dbh->prepare($query); + $sth->execute; + my $result=$sth->fetchrow; + $contract->{'booksellername'}=$result; + } + $template->param(loop => \...@loop); +} #---- END $OP eq DEFAULT +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl new file mode 100644 index 0000000..e7b3352 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl @@ -0,0 +1,248 @@ +<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --> +<title>Koha › Administration › Contracts › +<!-- TMPL_IF NAME="add_form" --> + <!-- TMPL_IF NAME="contractnumber" -->Modify contract '<!-- TMPL_VAR NAME="contractname" -->' +<!-- TMPL_ELSE -->New contract<!-- /TMPL_IF --> +<!-- /TMPL_IF --> +<!-- TMPL_IF NAME="add_validate" -->Data recorded<!-- /TMPL_IF --> +<!-- TMPL_IF NAME="delete_confirm" -->Confirm Deletion of Contract '<!-- TMPL_VAR NAME="contractnumber" -->'<!-- /TMPL_IF --> +<!-- TMPL_IF NAME="delete_confirmed" -->Contract Deleted<!-- /TMPL_IF --></title> +<!-- TMPL_INCLUDE NAME="doc-head-close.inc" --> +<!-- TMPL_INCLUDE NAME="calendar.inc" --> +<script type="text/javascript" src="<!-- TMPL_VAR NAME='themelang' -->/js/acq.js"></script> +<script type="text/javascript"> +//<![CDATA[ +// to check if the data are correctly entered. +function Check(ff) { + var ok=0; + var _alertString="Form not submitted because of the following problem(s)\n"; + _alertString +="-------------------------------------------------------------------\n\n"; + if (!(isNotNull(ff.booksellerid,0)) || !(isNum(ff.booksellerid,0))) { + ok=1; + _alertString += "- bookseller missing\n"; + } + if (!(isNotNull(ff.contractname,0))){ + ok=1; + _alertString += "- contract name missing\n"; + } + if (!(isNotNull(ff.contractdescription,0))) { + ok=1; + _alertString += "- description missing\n"; + } + if (!(CheckDate(ff.contractstartdate))){ + ok=1; + _alertString += "- contract start date missing\n"; + } + if (!(CheckDate(ff.contractenddate))){ + ok=1; + _alertString += "- contract end date missing\n"; + } + + if (!CompareDate(ff.contractstartdate.value, ff.contractenddate.value)) { + ok=1; + _alertString += "Bad date! Contract start date can not be after end date.\n"; + } + if (! CheckEndDate(ff.contractenddate.value)) { + ok=1; + _alertString += "End date before today, Invalid end date!\n"; + } + if (ok) { // if there is a problem + alert(_alertString); + return false; +} +// if all is good + ff.submit(); +} +//]]> +</script> +</head> +<body> +<!-- TMPL_INCLUDE NAME="header.inc" --> +<!-- TMPL_INCLUDE NAME="contracts-admin-search.inc" --> + +<div id="breadcrumbs"> + <a href="/cgi-bin/koha/mainpage.pl">Home</a> + › + <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> + › + <!-- TMPL_IF NAME="add_form" --> + <a href="/cgi-bin/koha/admin/aqcontract.pl">Contracts</a> + › + <!-- TMPL_IF NAME="contractnumber" -->Modify contract '<!-- TMPL_VAR NAME="contractname" -->' + <!-- TMPL_ELSE -->New contract + <!-- /TMPL_IF --> + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="add_validate" --> + <a href="/cgi-bin/koha/admin/aqcontract.pl">Contracts</a> + › Data recorded + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="delete_confirm" --> + <a href="/cgi-bin/koha/admin/aqcontract.pl">Contracts</a> + › Confirm Deletion of Contract <!-- TMPL_VAR NAME="contractnumber" --> + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="delete_confirmed" --> + <a href="/cgi-bin/koha/admin/aqcontract.pl">Contracts</a> › Contract Deleted + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="else" -->Contracts<!-- /TMPL_IF --> +</div> + +<div id="doc3" class="yui-t2"> + <div id="bd"> + <div id="yui-main"> + <div class="yui-b"> + <!-- TMPL_IF NAME="add_form" --> + <form name="Aform" action="<!-- TMPL_VAR NAME="script_name" -->" method="post"> + <input type="hidden" name="op" value="add_validate" /> + <input type="hidden" name="checked" value="0" /> + <!-- TMPL_IF NAME="contractnumber" --> + <h1>Modify contract <!-- TMPL_VAR NAME="contractname" --></h1> + <!-- TMPL_ELSE --> + <h1>New contract</h1> + <!-- /TMPL_IF --> + <fieldset class="rows"> + <ol> + <!-- TMPL_IF NAME="contractnumber" --> + <li><span class="label">Contract id </span><!-- TMPL_VAR NAME="contractnumber" --> + <input type="hidden" name="contractnumber" value="<!-- TMPL_VAR NAME="contractnumber" -->" /> + <input type="hidden" name="is_a_modif" value="1" /> + </li> + <!-- /TMPL_IF --> + <li><label for="contractname">Contract name</label> + <input type="text" name="contractname" id="contractname" size="40" maxlength="80" value="<!-- TMPL_VAR NAME="contractname" -->" /> + </li> + <li><label for="contractdescription">Contract description</label> + <input type="text" name="contractdescription" id="contractdescription" size="40" maxlength="80" value="<!-- TMPL_VAR NAME="contractdescription" -->" /> + </li> + <li><label for="booksellerid">bookseller</label> + <select id="booksellerid" name="booksellerid"> + <!-- TMPL_LOOP NAME="booksellerloop" --> + <!-- TMPL_IF NAME="selected" --> + <option value="<!-- TMPL_VAR NAME="id" -->" selected="selected"><!-- TMPL_VAR NAME="name" --></option> + <!-- TMPL_ELSE --> + <option value="<!-- TMPL_VAR NAME="id" -->"><!-- TMPL_VAR NAME="name" --></option> + <!-- /TMPL_IF --> + <!-- /TMPL_LOOP --> + </select> + </li> + <li><label for="contractstartdate">contract start date</label> + <input type="text" name="contractstartdate" id="contractstartdate" value="<!-- TMPL_VAR NAME="contractstartdate" -->"/> + <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="contractstartdate_button" alt="Show Calendar" /> + <script language="JavaScript" type="text/javascript"> + Calendar.setup( + { + inputField : "contractstartdate", + ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->", + button : "contractstartdate_button" + } + ); + </script> + </li> + <li><label for="contractenddate">contract end date</label> + <input type="text" name="contractenddate" id="contractenddate" value="<!-- TMPL_VAR NAME="contractenddate" -->" /> + <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="contractenddate_button" alt="Show Calendar" /> + <script language="JavaScript" type="text/javascript"> + Calendar.setup( + { + inputField : "contractenddate", + ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->", + button : "contractenddate_button" + } + ); + </script> + </li> + </ol> + </fieldset> + <fieldset class="action"> + <input type="button" value="Save" onclick="Check(this.form);" /> + </fieldset> + </form> + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="add_validate" --> + <h3>Data recorded</h3> + <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post"> + <input type="submit" value="OK" /> + </form> + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="delete_confirm" --> + <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post"> + <fieldset> + <legend>Confirm Deletion of Contract <!-- TMPL_VAR NAME="contractnumber" --></legend> + <table> + <tr><th scope="row">contractnumber:</th><td><!-- TMPL_VAR NAME="contractnumber" --></td></tr> + <tr><th scope="row">Contract Name:</th><td><!-- TMPL_VAR NAME="contractname" --></td></tr> + <tr><th scope="row">Contract Description:</th><td><!-- TMPL_VAR NAME="contractdescription" --></td></tr> + <tr><th scope="row">contractstartdate:</th><td><!-- TMPL_VAR NAME="contractstartdate" --></td></tr> + <tr><th scope="row">contractenddate:</th><td><!-- TMPL_VAR NAME="contractenddate" --></td></tr> + <tr><th scope="row">bookseller:</th><td><!-- TMPL_VAR NAME="booksellername" --></td></tr> + </table> + <fieldset class="action"> + <input type="hidden" name="op" value="delete_confirmed" /> + <input type="hidden" name="contractnumber" value="<!-- TMPL_VAR NAME="contractnumber" -->" /> + <input type="submit" value="Delete this Contract" /> + <a class="cancel" href="/cgi-bin/koha/admin/aqcontract.pl">Cancel</a> + </fieldset> + </fieldset> + </form> + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="delete_confirmed" --> + <h3>Contract Deleted</h3> + <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post"> + <input type="submit" value="OK" /> + </form> + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="else" --> + <div id="toolbar"> + <script type="text/javascript"> + //<![CDATA[ + // prepare DOM for YUI Toolbar + $(document).ready(function() { + yuiToolbar(); + }); + // YUI Toolbar Functions + function yuiToolbar() { + new YAHOO.widget.Button("newcontract"); + } + //]]> + </script> + <ul class="toolbar"> + <li><a id="newcontract" href="/cgi-bin/koha/admin/aqcontract.pl?op=add_form">New Contract</a></li> + </ul> + </div> + <h2>Contract Administration</h2> + <table> + <tr> + <th scope="col">contract id</th> + <th scope="col">Contract name</th> + <th scope="col">Contract description</th> + <th scope="col">contract start date</th> + <th scope="col">contract end date</th> + <th scope="col">bookseller</th> + <th scope="col" colspan="2"> </th> + </tr> + <!-- TMPL_LOOP NAME="loop" --> + <!-- TMPL_IF NAME="toggle" --> + <tr class="highlight"> + <!-- TMPL_ELSE --> + <tr> + <!-- /TMPL_IF --> + <td><!-- TMPL_VAR NAME="contractnumber" --></td> + <td> + <a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&contractnumber=<!-- TMPL_VAR NAME="contractnumber" -->"><!-- TMPL_VAR NAME="contractname" --></a> + </td> + <td><!-- TMPL_VAR NAME="contractdescription" --></td> + <td><!-- TMPL_VAR NAME="contractstartdate" --></td> + <td><!-- TMPL_VAR NAME="contractenddate" --></td> + <td><!-- TMPL_VAR NAME="booksellername" --></td> + <td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&contractnumber=<!-- TMPL_VAR NAME="contractnumber" -->">Edit</a></td> + <td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=delete_confirm&contractnumber=<!-- TMPL_VAR NAME="contractnumber" -->">Delete</a></td> + </tr> + <!-- /TMPL_LOOP --> + </table> + <!-- /TMPL_IF --> + </div> + </div> + <div class="yui-b"> + <!-- TMPL_INCLUDE NAME="admin-menu.inc" --> + </div> +</div> +<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" --> -- 1.6.0.4 _______________________________________________ Koha-patches mailing list [email protected] http://lists.koha.org/mailman/listinfo/koha-patches
