adding back patron images upload, no idea why it was removed
authorJoshua Ferraro <jmf@liblime.com>
Sun, 25 Nov 2007 01:17:24 +0000 (19:17 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Sun, 25 Nov 2007 22:27:10 +0000 (16:27 -0600)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/picture-upload.tmpl [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl
tools/picture-upload.pl [new file with mode: 0755]

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/picture-upload.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/picture-upload.tmpl
new file mode 100644 (file)
index 0000000..575c580
--- /dev/null
@@ -0,0 +1,78 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->\r
+<title>Koha &rsaquo; Tools &rsaquo; Upload Patron Images</title>\r
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->\r
+</head>\r
+<body>\r
+<!-- TMPL_INCLUDE NAME="header.inc" -->\r
+<!-- TMPL_INCLUDE NAME="patron-search.inc"-->\r
+\r
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; Upload Patron Images </div>\r
+\r
+<div id="doc3" class="yui-t2">\r
+\r
+   <div id="bd">\r
+    <div id="yui-main">\r
+    <div class="yui-b">\r
+<div class="yui-g">\r
+<div class="yui-u first">\r
+<h1>Upload Patron Images</h1>\r
+\r
+<!-- TMPL_IF name="total" -->\r
+       <ul class="data">\r
+               <li>Unpacking completed</li>\r
+       </ul>\r
+    <!-- TMPL_VAR NAME="total" --> Scanned\r
+    <!-- TMPL_VAR NAME="handled" --> Processed\r
+    <!-- TMPL_LOOP name="counts" -->\r
+        <!-- TMPL_VAR name="count" -->         Images moved from <!-- TMPL_VAR name="source" --> to <!-- TMPL_VAR name="dest" -->\r
+        <!-- TMPL_LOOP name="filenames" -->\r
+            <!-- TMPL_VAR name="source" --> To <!-- TMPL_VAR name="dest" -->\r
+        <!-- /TMPL_LOOP -->\r
+    <!-- /TMPL_LOOP -->\r
+<!-- TMPL_ELSE -->\r
+\r
+    <!-- TMPL_IF name="errors" -->\r
+        <!-- TMPL_LOOP name="errors" -->\r
+        <ul class="error">\r
+        <!-- TMPL_IF name="NOTZIP" -->\r
+            <li>The upload file does not appear to be a zip file.  The extention is not '.zip'.</li>\r
+        <!-- /TMPL_IF -->\r
+        <!-- TMPL_IF name="NOWRITETEMP" -->\r
+            <li>This script is not able to create/write to the necessary temporary directory.</li>\r
+        <!-- /TMPL_IF -->\r
+        <!-- TMPL_IF name="NOWRITEDEST" -->\r
+            <li>This script is not able to write to the patronpictures holding directory.</li>\r
+        <!-- /TMPL_IF -->\r
+        <!-- TMPL_IF name="EMPTYUPLOAD" -->\r
+            <li>The upload file appears to be empty.</li>\r
+        <!-- /TMPL_IF -->\r
+        <!-- /TMPL_LOOP -->\r
+    <!-- /TMPL_IF -->\r
+    <form method="post" action="/cgi-bin/koha/import/picture-upload.pl" enctype="multipart/form-data">\r
+    <ul>\r
+        <li>Select a file to upload to the server. Each .jpg file contained therein will be copied to the appropriate place on the server for patron pictures.</li>\r
+        <li>You can include multiple pictures in a .zip file.</li>\r
+        <li>There should be a DATALINK.TXT or IDLINK.TXT file for each group of pictures that has the cardnumber of the patron and the file containing that patrons picture.  One patron per line seperated by either ,'s or tabs.  Quotes around the fields are ignored.</li>\r
+    </ul>\r
+    <table>\r
+        <tr>\r
+            <th><label for="uploadfile">Select the .zip file to unpack: </label></th>\r
+            <td>\r
+                <input type="file" id="uploadfile" name="uploadfile" /><br />\r
+            </td>\r
+        </tr>\r
+    </table>\r
+        <input type="submit" value="Unpack" class="submit" />\r
+    </form>\r
+    \r
+<!-- /TMPL_IF -->\r
+\r
+</div>\r
+</div>\r
+</div>\r
+</div>\r
+<div class="yui-b">\r
+<!-- TMPL_INCLUDE NAME="tools-menu.inc" -->\r
+</div>\r
+</div>\r
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->\r
index f02eabe..8511763 100644 (file)
     <dt><a href="/cgi-bin/koha/tools/cleanborrowers.pl">Patrons (anonomize, bulk-delete)</a></dt>
     <dd>Delete old borrowers and anonymize circulation history (deletes borrower reading history)</dd>
 
+    <dt><a href="/cgi-bin/koha/tools/picture-upload.pl">Upload patron images</a></dt>
+       <dd>Upload patron images in batch or one at a time</dd>
+
     <dt><a href="/cgi-bin/koha/tools/scheduler.pl">Task Scheduler</a></dt>
     <dd>Schedule tasks to run</dd>
        
-       <dt><a href="/cgi-bin/koha/reviews/reviewswaiting.pl">Moderate reviews</a></dt>
-    <dd>Moderate reviews submitted by patrons</dd>
-
 </dl>
 </div>
 
diff --git a/tools/picture-upload.pl b/tools/picture-upload.pl
new file mode 100755 (executable)
index 0000000..c1834ca
--- /dev/null
@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+
+use File::Temp;
+use File::Copy;
+use CGI;
+use C4::Context;
+use C4::Auth;
+use C4::Output;
+
+#my $destdir = "/usr/local/koha/intranet/htdocs/intranet-tmpl/images/patronpictures";
+#my $uploadfile = shift @ARGV;
+my $input = new CGI;
+my $destdir = C4::Context->config('intrahtdocs') . "/patronimages";
+
+warn "DEST : $destdir";
+my ($template, $loggedinuser, $cookie)
+       = get_template_and_user({template_name => "tools/picture-upload.tmpl",
+                                       query => $input,
+                                       type => "intranet",
+                                       authnotrequired => 0,
+                                       flagsrequired => {management => 1, tools => 1},
+                                       debug => 0,
+                                       });
+
+my $uploadfilename = $input->param( 'uploadfile' );
+my $uploadfile = $input->upload( 'uploadfile' );
+my ( $total, $handled, @counts );
+
+if ( $uploadfile ) {
+    my $dirname = File::Temp::tempdir( CLEANUP => 1);
+    my ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => '.zip', UNLINK => 1 );
+    my ( @directories, %errors );
+
+    $errors{'NOTZIP'} = 1 unless ( $uploadfilename =~ /\.zip$/i );
+    $errors{'NOWRITETEMP'} = 1 unless ( -w "$dirname" );
+    $errors{'NOWRITEDEST'} = 1 unless ( -w "$destdir" );
+    $errors{'EMPTYUPLOAD'} = 1 unless ( length( $uploadfile ) > 0 );
+
+    if ( %errors ) {
+       $template->param( ERRORS => [ \%errors ] );
+    } else {
+       while ( <$uploadfile> ) {
+           print $tfh $_;
+       }
+
+       close $tfh;
+
+       `unzip $tempfile -d $dirname`;
+
+       push @directories, "$dirname";
+       foreach $recursive_dir ( @directories ) {
+           opendir $dir, $recursive_dir;
+           while ( my $entry = readdir $dir ) {
+               push @directories, "$recursive_dir/$entry" if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ );
+           }
+           closedir $dir;
+       }
+
+       foreach my $dir ( @directories ) {
+           $handled += handle_dir( $dir );
+       }
+
+       $total = scalar @directories;
+
+       $template->param(
+                        TOTAL => $total,
+                        HANDLED => $handled,
+                        COUNTS => \@counts,
+                        );
+    }
+}
+
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+sub handle_dir {
+    my ( $dir ) = @_;
+    my ( %count );
+    $count{filenames} = ();
+
+    return 0 unless ( -r "$dir/IDLINK.TXT" or -r "$dir/DATALINK.TXT" );
+
+    my $file = ( -r "$dir/IDLINK.TXT" ) ? "$dir/IDLINK.TXT" : "$dir/DATALINK.TXT";
+
+    open $fh, $file or { print "Openning $dir/$filename failed!\n" and return 0 };
+
+    while (my $line = <$fh>) {
+       chomp $line;
+
+       my ( $filename, $cardnumber );
+
+       my $delim = ($line =~ /\t/) ? "\t" : ",";
+
+       ($cardnumber, $filename) = split $delim, $line;
+       $cardnumber =~ s/[\"\r\n]//g;  # remove offensive characters
+       $filename =~ s/[\"\r\n]//g;
+
+       if ($cardnumber && $filename) {
+           my $result = move ( "$dir/$filename", "$destdir/$cardnumber.jpg" );
+           if ( $result ) {
+               $count{count}++;
+               push @{ $count{filenames} }, { source => $filename, dest => $cardnumber .".jpg" };
+           }
+       }
+    }
+    $count{source} = $dir;
+    $count{dest} = $destdir;
+    push @counts, \%count;
+
+    close $fh;
+
+    return 1;
+}