[Koha-patches] [PATCH 45/92] [MT1234] Code cleaning

Henri-Damien LAURENT henridamien.laurent at biblibre.com
Tue Dec 22 01:20:38 CET 2009


From: Jean-André Santoni <jeanandre.santoni at biblibre.com>

---
 admin/aqcontract.pl                                |  121 ++++++++------------
 .../prog/en/modules/admin/aqcontract.tmpl          |   14 +--
 2 files changed, 55 insertions(+), 80 deletions(-)

diff --git a/admin/aqcontract.pl b/admin/aqcontract.pl
index 9adedfe..0d9a858 100755
--- a/admin/aqcontract.pl
+++ b/admin/aqcontract.pl
@@ -51,8 +51,8 @@ my $script_name    = "/cgi-bin/koha/admin/aqcontract.pl";
 my $contractnumber = $input->param('contractnumber');
 my $booksellerid   = $input->param('booksellerid');
 my $op             = $input->param('op') || '';
-my @bookseller = GetBookSellerFromId("$booksellerid");
 
+my @bookseller = GetBookSellerFromId($booksellerid);
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {   template_name   => "admin/aqcontract.tmpl",
@@ -69,7 +69,7 @@ $template->param(
     contractnumber => $contractnumber,
     searchfield    => $searchfield, 
     booksellerid   => $booksellerid,
-    name           => $bookseller[0]->{name},
+    booksellername => $bookseller[0]->{name},
     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
 );
 
@@ -77,7 +77,6 @@ $template->param(
 if ( $op eq 'add_form' ) {
     $template->param( add_form => 1 );
     my $data;
-    my $booksellername;
 
     #---- if primkey exists, it's a modify action, so read values to modify...
     if ($contractnumber) {
@@ -86,14 +85,6 @@ if ( $op eq 'add_form' ) {
         $sth->execute($contractnumber);
         $data = $sth->fetchrow_hashref;
         $sth->finish;
-
-        for ( @bookseller ) {
-            $booksellername = $$_{name} if $$_{id} eq $$data{booksellerid};
-        }
-    } else {
-        for ( @bookseller ) {
-            $booksellername = $$_{name} if $$_{id} eq $booksellerid;
-        }
     }
 
     $template->param(
@@ -102,54 +93,51 @@ if ( $op eq 'add_form' ) {
         contractdescription      => $data->{'contractdescription'},
         contractstartdate        => format_date( $data->{'contractstartdate'} ),
         contractenddate          => format_date( $data->{'contractenddate'} ),
-        booksellername           => $booksellername,
         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
     );
 
     # END $OP eq ADD_FORM
-
-    #ADD_VALIDATE: called by add_form, used to insert/modify data in DB
 }
+#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?booksellerid=$booksellerid\"></html>";
-  exit;
-
-  # END $OP eq ADD_VALIDATE
+    $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?booksellerid=$booksellerid\"></html>";
+    exit;
 
-#DELETE_CONFIRM: called by default form, used to confirm deletion of data in DB
+    # 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 );
 
@@ -178,9 +166,8 @@ elsif ( $op eq 'delete_confirm' ) {
     );
 
     # END $OP eq DELETE_CONFIRM
-
-    #DELETE_CONFIRMED: called by delete_confirm, used to effectively confirm deletion of data in DB
 }
+#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;
@@ -192,30 +179,22 @@ elsif ( $op eq 'delete_confirmed' ) {
     exit;
 
     # END $OP eq DELETE_CONFIRMED
-    # DEFAULT: Builds a list of contracts and displays them
-} else {
+}
+# 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;
-            }
+            push @loop, {
+                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'},
+            };
         }
     }
     for my $contract (@loop) {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl
index 4f3a951..79f86a9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl
@@ -57,7 +57,7 @@ function Check(ff) {
     &rsaquo;
     <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
     &rsaquo;
-    <a href="/cgi-bin/koha/acqui/supplier.pl?supplierid=<!--TMPL_VAR name="booksellerid" -->"><!-- TMPL_VAR name="name" --></a>
+    <a href="/cgi-bin/koha/acqui/supplier.pl?supplierid=<!--TMPL_VAR name="booksellerid" -->"><!-- TMPL_VAR name="booksellername" --></a>
     &rsaquo;
     <!-- TMPL_IF NAME="add_form" -->
         <a href="/cgi-bin/koha/admin/aqcontract.pl?booksellerid=<!-- TMPL_VAR  NAME="booksellerid" -->">Contracts</a>
@@ -193,7 +193,7 @@ function Check(ff) {
                         <li><a id="newcontract" href="/cgi-bin/koha/admin/aqcontract.pl?op=add_form&amp;booksellerid=<!-- TMPL_VAR name="booksellerid" -->">New Contract</a></li>
                     </ul>
                 </div>
-                <h2>Contract(s) of <!-- TMPL_VAR name="name" --></h2>
+                <h2>Contract(s) of <!-- TMPL_VAR name="booksellername" --></h2>
                 <!-- TMPL_IF name="loop" -->
                     <table>
                         <tr>
@@ -204,13 +204,9 @@ function Check(ff) {
                             <th scope="col" colspan="2">&nbsp; </th>
                         </tr>
                     <!-- TMPL_LOOP NAME="loop" -->
-                        <!-- TMPL_IF NAME="toggle" -->
-                            <tr class="highlight">
-                        <!-- TMPL_ELSE -->
-                            <tr>
-                        <!-- /TMPL_IF -->
-                            <td>
-                                <a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&amp;contractnumber=<!-- TMPL_VAR NAME="contractnumber" -->"><!-- TMPL_VAR NAME="contractname" --></a>
+                        <!-- TMPL_IF NAME="__even__" --><tr class="highlight"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
+                        <td>
+                            <a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&amp;contractnumber=<!-- TMPL_VAR NAME="contractnumber" -->"><!-- TMPL_VAR NAME="contractname" --></a>
                         </td>
                         <td><!-- TMPL_VAR NAME="contractdescription" --></td>
                         <td><!-- TMPL_VAR NAME="contractstartdate" --></td>
-- 
1.6.3.3




More information about the Koha-patches mailing list