currencies admin: managing active field

This commit is contained in:
Paul Poulain 2009-04-28 21:36:07 +02:00 committed by Henri-Damien LAURENT
parent fd882db020
commit 6358e6b580
2 changed files with 57 additions and 16 deletions

View file

@ -69,6 +69,9 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
debug => 1,
});
$searchfield=~ s/\,//g;
$template->param(searchfield => $searchfield,
script_name => $script_name);
@ -88,6 +91,7 @@ if ($op eq 'add_form') {
foreach (keys %$data) {
$template->param($_ => $data->{$_});
}
my $date = $template->param('timestamp');
($date) and $template->param('timestamp' => format_date($date));
# END $OP eq ADD_FORM
@ -95,15 +99,37 @@ if ($op eq 'add_form') {
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
$template->param(add_validate => 1);
my $check = $dbh->prepare("select * from currency where currency = ?");
my $dbh = C4::Context->dbh;
my $check = $dbh->prepare("select count(*) as count from currency where currency = ?");
$dbh->do("UPDATE currency SET active = 0") if ( $input->param('active') == 1);
$check->execute($input->param('currency'));
if ( $check->fetchrow ) {
my $sth = $dbh->prepare("UPDATE currency SET rate = ?, symbol = ?, timestamp = ? WHERE currency = ?");
$sth->execute($input->param('rate'),$input->param('symbol'),C4::Dates->new->output('iso'),$input->param('currency'));
} else {
my $sth = $dbh->prepare("INSERT INTO currency (currency, rate, symbol) VALUES (?,?,?)");
$sth->execute($input->param('currency'),$input->param('rate'),$input->param('symbol'));
}
my $count = $check->fetchrow ;
if ( $count > 0 )
{
my $sth = $dbh->prepare(qq|
UPDATE currency
SET rate = ?,
symbol = ?,
active = ?
WHERE currency = ? | );
$sth->execute( $input->param('rate'),
$input->param('symbol'),
$input->param('active'),
$input->param('currency'), );
}
else
{
my $sth = $dbh->prepare(qq|
INSERT INTO currency (currency, rate, symbol, active) VALUES (?,?,?,?) |);
$sth->execute( $input->param('currency'),
$input->param('rate'),
$input->param('symbol'),
$input->param('active'), );
}
# END $OP eq ADD_VALIDATE
################## DELETE_CONFIRM ##################################
# called by default form, used to confirm deletion of data in DB

View file

@ -42,11 +42,9 @@
<!-- TMPL_INCLUDE NAME="header.inc" -->
<!-- TMPL_INCLUDE NAME="currencies-admin-search.inc" -->
<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
&rsaquo; <a href="<!-- TMPL_VAR NAME="script_name" -->">Currencies &amp; Exchange Rates</a>
&rsaquo; <!-- TMPL_IF NAME="add_form" --><!-- TMPL_IF NAME="searchfield" -->Modify Currency '<!-- TMPL_VAR NAME="searchfield" -->'<!-- TMPL_ELSE -->New Currency<!-- /TMPL_IF --><!-- /TMPL_IF -->
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/currency.pl">Currencies &amp; Exchange Rates</a> &rsaquo; <!-- TMPL_IF NAME="add_form" --><!-- TMPL_IF NAME="searchfield" -->Modify Currency '<!-- TMPL_VAR NAME="searchfield" -->'<!-- TMPL_ELSE -->New Currency<!-- /TMPL_IF --><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="add_validate" -->Data Recorded<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="delete_confirm" -->Confirm Deletion of Currency '<span class="ex"><!-- TMPL_VAR NAME="searchfield" --></span>'<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="delete_confirmed" -->Currency Deleted<!-- /TMPL_IF -->
@ -94,11 +92,18 @@
<label for="symbol">Symbol: </label>
<input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="<!-- TMPL_VAR NAME="symbol" -->" />
</li>
<li>
<label for="currency">Last Updated: </label><!-- TMPL_VAR NAME="timestamp" -->
</li>
</ol>
</fieldset>
<li>
<label for="currency">Active: </label>
<input type="checkbox" id="active" name="active" value="1"
<!-- TMPL_IF NAME="active" --> checked <!-- /TMPL_IF --> />
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="submit" value="Submit" onclick="Check(this.form)" /> <a class="cancel" href="<!-- TMPL_VAR NAME="script_name" -->">Cancel</a>
@ -168,7 +173,8 @@
<th>Rate</th>
<th>Symbol</th>
<th>Last Updated</th>
<th colspan="2">&nbsp;</th>
<th>Active</th>
<th colspan="2">Actions&nbsp;</th>
</tr>
<!-- TMPL_LOOP NAME="loop" -->
<!-- TMPL_UNLESS NAME="__odd__" -->
@ -180,11 +186,20 @@
<td><!-- TMPL_VAR NAME="rate" --></td>
<td><!-- TMPL_VAR NAME="symbol" ESCAPE="HTML" --></td>
<td><!-- TMPL_VAR NAME="timestamp" --></td>
<td><!-- TMPL_IF NAME="active" -->
<font COLOR="#00FF00">✓</font>
<!-- /TMPL_IF -->
</td>
<td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&amp;searchfield=<!-- TMPL_VAR NAME="currency" -->">Edit</a></td>
<td><a href="<!-- TMPL_VAR NAME="script_name" -->?op=delete_confirm&amp;searchfield=<!-- TMPL_VAR NAME="currency" -->">Delete</a></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
<br>
<p><b>Hint:</b> Your 'active' currency should have it's exchange rate set to '1.00000'</p>
<!-- TMPL_IF NAME="offsetgtzero" -->
<a href="<!-- TMPL_VAR NAME="script_name" -->?offset=<!-- TMPL_VAR NAME="prevpage" -->">&lt;&lt; Previous</a>