Bugfix for Bug 1618: First Installment
authorChris <cnighswonger@foundations.edu>
Fri, 1 Feb 2008 00:27:01 +0000 (18:27 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Sun, 3 Feb 2008 13:23:41 +0000 (07:23 -0600)
This corrects the major template issues once files are uploaded.
The changes need dressing up a bit still.

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/picture-upload.tmpl
tools/picture-upload.pl

index 143483c..68811ce 100644 (file)
 
    <div id="bd">
     <div id="yui-main">
+<!-- TMPL_IF name="TOTAL" -->
     <div class="yui-b">
-<h1>Upload Patron Images</h1>
-<div class="yui-g">
-<div class="yui-u first">
-<!-- TMPL_IF name="total" -->
+    <h1>Patron Images Successfully Uploaded</h1>
+    <div class="yui-g">
+    <div class="yui-u first">
        <ul class="data">
-               <li>Unpacking completed</li>
-       </ul>
-    <!-- TMPL_VAR NAME="total" --> Scanned
-    <!-- TMPL_VAR NAME="handled" --> Processed
-    <!-- TMPL_LOOP name="counts" -->
-        <!-- TMPL_VAR name="count" -->         Images moved from <!-- TMPL_VAR name="source" --> to <!-- TMPL_VAR name="dest" -->
-        <!-- TMPL_LOOP name="filenames" -->
-            <!-- TMPL_VAR name="source" --> To <!-- TMPL_VAR name="dest" -->
-        <!-- /TMPL_LOOP -->
+           <li>Unpacking completed</li>
+            <li><!-- TMPL_VAR NAME ="TOTAL" --> directories scanned.</li>
+            <li><!-- TMPL_VAR NAME="HANDLED" --> directories processed.</li>
+        </ul>
+        <!-- TMPL_LOOP name="COUNTS" -->
+           <ul class="data">
+                <li><!-- TMPL_VAR name="TCOUNTS" --> image(s) moved from <!-- TMPL_VAR name="source" --> to <!-- TMPL_VAR name="dest" -->:</li>
+            </ul>
+                <!-- TMPL_LOOP name="filenames" -->
+                    <ul class="data">
+                    <li><!-- TMPL_VAR name="source" --> To <!-- TMPL_VAR name="dest" --></li>
+                    </ul>
+                <!-- /TMPL_LOOP -->
     <!-- /TMPL_LOOP -->
+    </div>
+    </div>
+    <div class="yui-u">
+    <a id="uploadmore" class="btn blue" href="/cgi-bin/koha/tools/picture-upload.pl">Upload Images</a>
+    <a id="doneupload" class="btn blue" href="/cgi-bin/koha/tools/tools-home.pl">Return to Tools</a>
+    </div>
 <!-- TMPL_ELSE -->
 
+<div class="yui-b">
+<h1>Upload Patron Images</h1>
+<div class="yui-g">
+<div class="yui-u first">
     <!-- TMPL_IF name="ERRORS" -->
         <div class="dialog alert"><ul>
         <!-- TMPL_LOOP name="ERRORS" -->
     </ul>
 </div>
 </div>
+</div>
+</div>
 <!-- /TMPL_IF -->
-
 </div>
 </div>
+
 <div class="yui-b">
 <!-- TMPL_INCLUDE NAME="tools-menu.inc" -->
 </div>
index c5b5aec..2203f5d 100755 (executable)
@@ -7,6 +7,8 @@ use C4::Context;
 use C4::Auth;
 use C4::Output;
 
+my $DEBUG = 1;
+
 #my $destdir = "/usr/local/koha/intranet/htdocs/intranet-tmpl/images/patronpictures";
 #my $uploadfile = shift @ARGV;
 my $input = new CGI;
@@ -35,7 +37,9 @@ my ( $total, $handled, @counts );
 
 if ( $uploadfile ) {
     my $dirname = File::Temp::tempdir( CLEANUP => 1);
+    warn "dirname = $dirname" if $DEBUG;
     my ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => '.zip', UNLINK => 1 );
+    warn "tempfile = $tempfile" if $DEBUG;
     my ( @directories, %errors );
 
     $errors{'NOTZIP'} = 1 unless ( $uploadfilename =~ /\.zip$/i );
@@ -59,6 +63,7 @@ if ( $uploadfile ) {
            opendir $dir, $recursive_dir;
            while ( my $entry = readdir $dir ) {
                        push @directories, "$recursive_dir/$entry" if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ );
+                        warn "$recursive_dir/$entry" if $DEBUG;
            }
            closedir $dir;
        }
@@ -68,11 +73,12 @@ if ( $uploadfile ) {
        }
 
        $total = scalar @directories;
-
+        warn "Total files processed: $total" if $DEBUG;
        $template->param(
                         TOTAL => $total,
                         HANDLED => $handled,
                         COUNTS => \@counts,
+                        TCOUNTS => scalar(@counts),
                         );
     }
 }
@@ -96,9 +102,11 @@ sub handle_dir {
                my $delim = ($line =~ /\t/) ? "\t" : ",";
                ($cardnumber, $filename) = split $delim, $line;
                $cardnumber =~ s/[\"\r\n]//g;  # remove offensive characters
-               $filename   =~ s/[\"\r\n]//g;
+               $filename   =~ s/[\"\r\n\s]//g;
+                warn "Cardnumber: $cardnumber Filename: $filename" if $DEBUG;
 
                if ($cardnumber && $filename) {
+                    warn "Source: $dir/$filename Target: $destdir/$cardnumber.jpg" if $DEBUG;
                my $result = move ( "$dir/$filename", "$destdir/$cardnumber.jpg" );
                        if ( $result ) {
                                $count{count}++;