[Koha-cvs] koha koha-tmpl/intranet-tmpl/prog/en/tools/expo... [rel_3_0]

Antoine Farnault antoine at koha-fr.org
Wed Dec 20 12:14:59 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	Antoine Farnault <toins>	06/12/20 11:14:59

Modified files:
	koha-tmpl/intranet-tmpl/prog/en/tools: export.tmpl 
	tools          : export.pl 

Log message:
	Some enhancements: now allow to export into marc or xml, to delete some field/subfield from exported record...

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.3.2.4&r2=1.3.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/tools/export.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.5&r2=1.1.2.6

Patches:
Index: koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl
===================================================================
RCS file: /sources/koha/koha/koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl,v
retrieving revision 1.3.2.4
retrieving revision 1.3.2.5
diff -u -b -r1.3.2.4 -r1.3.2.5
--- koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl	17 Nov 2006 13:18:59 -0000	1.3.2.4
+++ koha-tmpl/intranet-tmpl/prog/en/tools/export.tmpl	20 Dec 2006 11:14:59 -0000	1.3.2.5
@@ -1,30 +1,86 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 MARC biblio export
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+
 <!-- TMPL_INCLUDE NAME="menus.inc" -->
 <!-- TMPL_INCLUDE NAME="menu-tools.inc" -->
 
-	<div id="bloc25">
-		<h2 class="parameters">Select biblios to export</h2>
-		<form method="post">
-			<p><label>from biblio number</label><input type="text" name="StartingBiblionumber">
-			to biblio number : <input type="text" name="EndingBiblionumber"></p>
-			<p><label>Document type</label><!--TMPL_VAR Name="CGIitemtype"--></p>
-			<p><label>Branch</label><select name="branch">
-			<option value="">Default</option>
+<h2>Select biblios to export</h2>
+<p>
+    <b>Note : The items are exported by this tool.</b>
+</p>
+
+<form method="post" action="/cgi-bin/koha/tools/export.pl">
+    <fieldset>
+    <legend>
+        Records
+    </legend>
+    	<p>
+    	    <label for="start">from biblio number</label>
+    	    <input id="start" type="text" name="StartingBiblionumber" size="5" />
+    	    <label for="end">to biblio number :</label>
+    	    <input id="end" type="text" name="EndingBiblionumber" size="5" />
+    	</p>
+    	
+    	<p>
+    	    <label for="itemtypes" >Document type</label>
+            <select name="itemtype">
+                <option value="">-- All --</option>
+                <!-- TMPL_LOOP NAME="itemtypeloop" -->
+                <option value="<!-- TMPL_VAR name="value" -->"
+                    <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->>
+                    <!-- TMPL_VAR name="description" -->
+                    </option>
+                <!-- /TMPL_LOOP -->
+            </select>
+    	</p>
+    	
+    	<p>
+    	    <label for="branch">Branch</label>
+    	    <select id="branch" name="branch">
+    	    <option value="">-- All --</option>
                         <!-- TMPL_LOOP name="branchloop" -->
-                                <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name
-="branchname" --></option>
+                    <option value="<!-- TMPL_VAR name="value" -->"
+                     <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->>
+                        <!-- TMPL_VAR name="branchname" -->
+                    </option>
                         <!-- /TMPL_LOOP -->
                         </select>
-</p>
-			<p><label>from itemcallnumber</label><input type="text" name="start_callnumber">
-			to itemcallnumber : <input type="text" name="end_callnumber"></p>
-			<p><label>Limit to </label><input type="text" name="limit"> first biblio</p>
-			<p>Note : the items are exported by this tool</p>
-			<input type="hidden" name="op" value="export">
-			<input type="submit" value="Export" class="button">
-		</form>
-	</div>
-</div>
+        </p>
+    	<p>
+    	    <label for="startcn">from itemcallnumber</label>
+    	    <input id="startcn" type="text" name="start_callnumber" size="5" />
+        	<label for="endcn">to itemcallnumber : </label>
+        	<input id="endcn" type="text" name="end_callnumber" size="5" />
+        </p>
+    </fieldset>
+    <fieldset>
+    <legend>
+        Options
+    </legend>
+        <label for="dont_export_item">Don't export items</label>
+        <input id="dont_export_item" type="checkbox" name="dont_export_item" />
+        <br />
+        <label for="dont_export_fields">Don't export fields</label>
+        <input id="dont_export_fields" type="text" name="dont_export_fields" />
+        <i>splitted by a blank. (for example: 100a 200 606)</i>
+        <br />
+    </fieldset>
+    <fieldset>
+    <legend>
+        Output format
+    </legend>
+    	<p>
+    	    <label for="output_format">into </label>
+    	    <select id="output_format" name="output_format">
+    	        <option value="marc">marc</option>
+    	        <option value="xml">xml</option>
+    	    </select>
+    	    format.
+    	</p>
+	</fieldset>
+	<input type="hidden" name="op" value="export" />
+	<input type="submit" value="Export" class="button" />
+</form>
+
 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->

Index: tools/export.pl
===================================================================
RCS file: /sources/koha/koha/tools/export.pl,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -b -r1.1.2.5 -r1.1.2.6
--- tools/export.pl	14 Dec 2006 15:41:55 -0000	1.1.2.5
+++ tools/export.pl	20 Dec 2006 11:14:59 -0000	1.1.2.6
@@ -16,17 +16,16 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: export.pl,v 1.1.2.5 2006/12/14 15:41:55 toins Exp $
+# $Id: export.pl,v 1.1.2.6 2006/12/20 11:14:59 toins Exp $
 
 use strict;
 require Exporter;
-use C4::Database;
 use C4::Auth;
 use C4::Interface::CGI::Output;
 use C4::Output;  # contains gettemplate
-use C4::Biblio;
+use C4::Biblio;  # GetMarcBiblio GetXmlBiblio
 use CGI;
-use C4::Koha;
+use C4::Koha;    # GetItemTypes
 use C4::Branch; # GetBranches
 
 my $query = new CGI;
@@ -34,95 +33,137 @@
 my $dbh=C4::Context->dbh;
 
 if ($op eq "export") {
+
     print $query->header('Content-Type: text/marc');
+    
     my $StartingBiblionumber = $query->param("StartingBiblionumber");
     my $EndingBiblionumber = $query->param("EndingBiblionumber");
-    my $format = $query->param("format");
+    my $output_format         = $query->param("output_format");
     my $branch = $query->param("branch");
+    my $itemtype              = $query->param("itemtype");
     my $start_callnumber = $query->param("start_callnumber");
     my $end_callnumber = $query->param("end_callnumber");
-    my $limit = $query->param("limit");
-    my $strsth;
-    $strsth="select bibid from marc_biblio ";
-    if ($StartingBiblionumber && $EndingBiblionumber) {
-        $strsth.=" where biblionumber>=$StartingBiblionumber and biblionumber<=$EndingBiblionumber ";
-    }elsif ($format) {
-        if ($strsth=~/ where/){
-            $strsth=~s/ where (.*)/,biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\' and $1/;
-        }else {
-            $strsth.=",biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\'";
-        }
-    } elsif ($branch) {
-        if ($strsth=~/ where/){
-            $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\' and $1/;
-        }else {
-            $strsth.=",items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\'";
-        }
-    } elsif ($start_callnumber && $end_callnumber) {
-        $start_callnumber=~s/\*/\%/g;
-        $start_callnumber=~s/\?/\_/g;
-        $end_callnumber=~s/\*/\%/g;
-        $end_callnumber=~s/\?/\_/g;
-        if ($strsth=~/,items/){
-            $strsth.=" and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\'";
-        } else {
-            if ($strsth=~/ where/){
-                $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' and $1/;
-            }else {
-                $strsth=~",items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' ";
+    my $dont_export_items     = $query->param("dont_export_item");
+    my $dont_export_fields    = $query->param("dont_export_fields");
+    my @sql_params;
+    my $query = " SELECT DISTINCT biblioitems.biblionumber
+                  FROM biblioitems,items
+                  WHERE biblioitems.biblionumber=items.biblionumber ";
+                  
+    if ( $StartingBiblionumber ) {
+        $query .= " AND biblioitems.biblionumber <= ? ";
+        push @sql_params, $StartingBiblionumber;
+    }
+    
+    if ( $EndingBiblionumber ) {
+        $query .= " AND biblioitems.biblionumber >= ? ";
+        push @sql_params, $StartingBiblionumber;    
+    }
+    
+    if ( $branch ) {
+        $query .= " AND biblioitems.biblionumber = items.biblionumber AND homebranch = ? ";
+        push @sql_params, $branch;
+    }
+    
+    if ( $start_callnumber ) {
+        $query .= " AND biblioitems.biblionumber = items.biblionumber AND itemcallnumber <= ? ";
+        push @sql_params, $start_callnumber;
             }
+    
+    if ( $end_callnumber ) {
+        $query .= " AND biblioitems.biblionumber = items.biblionumber AND itemcallnumber >= ? ";
+        push @sql_params, $end_callnumber;
         }
+    
+    if ( $itemtype ) {
+        $query .= " AND biblioitems.itemtype = ?";
+        push @sql_params, $itemtype;
+    }
+
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@sql_params);
+
+    while (my ($biblionumber) = $sth->fetchrow) {
+        my $record = GetMarcBiblio($biblionumber);
+        if ( $dont_export_items) {
+            # now, find where the itemnumber is stored & extract only the item
+            my ( $itemnumberfield, $itemnumbersubfield ) =
+                MARCfind_marc_from_kohafield( $dbh, 'items.itemnumber', '' );
+
+            # and delete it.
+            foreach ($record->field($itemnumberfield)){
+                $record->delete_field($record->field($itemnumberfield));
+            }
+        }
+        
+        if ( $dont_export_fields ) {
+            my @fields = split " ", $dont_export_fields;
+            foreach ( @fields ) {
+                /^(\d*)(\w)?$/;
+                my $field = $1;
+                my $subfield = $2;
+                if($subfield){
+                    $record->field($field)->delete_subfields($subfield);
+                }
+                else {
+                    $record->delete_field($record->field($field));
+                }
+            }
+        }
+        if ( $output_format eq "xml" ) {
+            print $record->as_xml; # Need marc::record 2
+        }
+        else {
+            print $record->as_formatted; 
+        }
+    }
+    exit;
+    
+} # if export
+
+else {
+
+    my $itemtypes = GetItemTypes;
+    my @itemtypesloop;
+    foreach my $thisitemtype (sort keys %$itemtypes) {
+        my %row =
+            (
+                value => $thisitemtype,
+                description => $itemtypes->{$thisitemtype}->{'description'},
+            );
+       push @itemtypesloop, \%row;
     }
-    $strsth.=" order by marc_biblio.biblionumber ";
-    $strsth.= "LIMIT 0,$limit " if ($limit);
-    warn "requete marc.pl : ".$strsth;
-    my $req=$dbh->prepare($strsth);
-    $req->execute;
-    while (my ($bibid) = $req->fetchrow) {
-        my $record = GetMarcBiblio($bibid);
-
-        print $record->as_usmarc();
-    }
-} else {
-    my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
-    $sth->execute;
-    my  @itemtype;
-    my %itemtypes;
-    push @itemtype, "";
-    $itemtypes{''} = "";
-    while (my ($value,$lib) = $sth->fetchrow_array) {
-            push @itemtype, $value;
-            $itemtypes{$value}=$lib;
-    }
-    
-    my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
-                            -values   => \@itemtype,
-                            -default  => '',
-                            -labels   => \%itemtypes,
-                            -size     => 1,
-                            -multiple => 0 );
-    $sth->finish;
     
     my $branches = GetBranches;
+    my $branch   = GetBranch($query,$branches);
     my @branchloop;
     foreach my $thisbranch (keys %$branches) {
-#             my $selected = 1 if $thisbranch eq $branch;
-            my %row =(value => $thisbranch,
-#                                     selected => $selected,
+        my $selected = 1 if $thisbranch eq $branch;
+        my %row = (
+            value => $thisbranch,
+            selected => $selected,
                                     branchname => $branches->{$thisbranch}->{'branchname'},
                             );
             push @branchloop, \%row;
     }
     
     my ($template, $loggedinuser, $cookie)
-    = get_template_and_user({template_name => "tools/export.tmpl",
+    = get_template_and_user
+    (
+        {
+            template_name => "tools/export.tmpl",
                     query => $query,
                     type => "intranet",
                     authnotrequired => 0,
                     flagsrequired => {parameters => 1, management => 1, tools => 1},
                     debug => 1,
-                    });
-    $template->param(branchloop=>\@branchloop,CGIitemtype=>$CGIitemtype);
+         }
+    );
+    
+    $template->param(
+        branchloop   => \@branchloop,
+        itemtypeloop => \@itemtypesloop
+    );
+    
     output_html_with_http_headers $query, $cookie, $template->output;
 }
-





More information about the Koha-cvs mailing list