[Koha-patches] [PATCH 16/78] currencies admin: managing active field

paul.poulain at biblibre.com paul.poulain at biblibre.com
Thu May 28 18:32:26 CEST 2009


From: Paul Poulain <paul.poulain at biblibre.com>

---
 admin/currency.pl                                  |   59 ++++++++++++++------
 .../prog/en/modules/admin/currency.tmpl            |   25 ++++++++-
 2 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/admin/currency.pl b/admin/currency.pl
index 145dc3f..1c7c32a 100755
--- a/admin/currency.pl
+++ b/admin/currency.pl
@@ -65,23 +65,26 @@ sub StringSearch  {
 }
 
 my $input = new CGI;
-my $searchfield=$input->param('searchfield');
+
+my $searchfield = $input->param('searchfield');
+my $active      = $input->param('active');
+my $offset      = $input->param('offset');
 #my $branchcode=$input->param('branchcode');
-my $offset=$input->param('offset');
 my $script_name="/cgi-bin/koha/admin/currency.pl";
 
 my $pagesize=20;
 my $op = $input->param('op');
 $searchfield=~ s/\,//g;
 
-my ($template, $loggedinuser, $cookie) 
-    = get_template_and_user({template_name => "admin/currency.tmpl",
-                             query => $input,
-                             type => "intranet",
-			     flagsrequired => {parameters => 1},
-			     authnotrequired => 0,
-                             debug => 1,
-                             });
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {   template_name   => "admin/currency.tmpl",
+        query           => $input,
+        type            => "intranet",
+        flagsrequired   => { parameters => 1 },
+        authnotrequired => 0,
+        debug           => 1,
+    }
+);
 
 $template->param(searchfield => $searchfield,
 		 script_name => $script_name);
@@ -99,10 +102,12 @@ if ($op eq 'add_form') {
 		$sth->execute($searchfield);
 		$data=$sth->fetchrow_hashref;
 		$sth->finish;
+
 	}
 	foreach (keys %$data) {
 		$template->param($_ => $data->{$_});
 	}
+
 	my $date = $template->param('timestamp');
 	($date) and $template->param('timestamp' => format_date($date));
 													# END $OP eq ADD_FORM
@@ -111,21 +116,38 @@ if ($op eq 'add_form') {
 } elsif ($op eq 'add_validate') {
 	$template->param(add_validate => 1);
 	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);
 
-	my $check = $dbh->prepare("select * from currency where currency = ?");
 	$check->execute($input->param('currency'));
-	if ( $check->fetchrow )
+	my $count =   $check->fetchrow ;
+	if ( $count > 0  )
 	{
-		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'));
+		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'),  );
 		$sth->finish;
 	}
 	else
 	{
-		my $sth = $dbh->prepare("INSERT INTO currency (currency, rate, symbol) VALUES (?,?,?)");
-		$sth->execute($input->param('currency'),$input->param('rate'),$input->param('symbol'));
+		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'),       );
 		$sth->finish;
-	}	 
+	}
 
 	$check->finish;
 													# END $OP eq ADD_VALIDATE
@@ -173,6 +195,9 @@ if ($op eq 'add_form') {
 			  symbol => $results->[$i]{'symbol'},
 		   timestamp => format_date($results->[$i]{'timestamp'}),
 		);
+
+		$row{'active'} = 1  if  $results->[$i]{'active'} == 1;
+
 		($i % 2) and $row{toggle} = 1;
 		push @loop, \%row;
 	}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl
index bfe3623..c9b7b60 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl
@@ -71,6 +71,11 @@
 <!-- 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="/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 -->
@@ -130,9 +135,17 @@
 			<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>
+
+        <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>
 		
@@ -201,7 +214,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_IF NAME="toggle" -->
@@ -213,11 +227,20 @@
 			<td><!-- TMPL_VAR NAME="rate" --></td>
 			<td><!-- TMPL_VAR NAME="symbol" --></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>
-- 
1.6.0.4



More information about the Koha-patches mailing list