Adding Update/Delete functions to patron image management on Details page
authorChris Nighswonger <cnighswonger@foundations.edu>
Thu, 6 Mar 2008 13:05:31 +0000 (08:05 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 6 Mar 2008 18:14:44 +0000 (12:14 -0600)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Members.pm
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/tools/picture-upload.tmpl
tools/picture-upload.pl

index 6e81ea3..f01fb4e 100644 (file)
@@ -57,8 +57,10 @@ BEGIN {
                &GetRoadTypeDetails 
                &GetSortDetails
                &GetTitles
+
                 &GetPatronImage
                 &PutPatronImage
+                &RmPatronImage
 
                &GetMemberAccountRecords
                &GetBorNotifyAcctRecord
@@ -1708,7 +1710,7 @@ Returns the mimetype and binary image data of the image for the patron with the
 
 sub GetPatronImage {
     my ($cardnumber) = @_;
-    warn "Cardnumber passed to GetPatronImage is $cardnumber"; # if $debug;
+    warn "Cardnumber passed to GetPatronImage is $cardnumber" if $debug;
     my $dbh = C4::Context->dbh;
     my $query = "SELECT mimetype, imagefile FROM patronimage WHERE cardnumber = ?;";
     my $sth = $dbh->prepare($query);
@@ -1732,15 +1734,36 @@ sub PutPatronImage {
     my ($cardnumber, $mimetype, $imgfile) = @_;
     warn "Parameters passed in: Cardnumber=$cardnumber, Mimetype=$mimetype, " . ($imgfile ? "Imagefile" : "No Imagefile") if $debug;
     my $dbh = C4::Context->dbh;
-    my $query = "INSERT INTO patronimage (cardnumber, mimetype, imagefile) VALUES (?,?,?) ON DUPLICATE KEY UPDATE cardnumber = ?;";
+    my $query = "INSERT INTO patronimage (cardnumber, mimetype, imagefile) VALUES (?,?,?) ON DUPLICATE KEY UPDATE imagefile = ?;";
     my $sth = $dbh->prepare($query);
-    $sth->execute($cardnumber,$mimetype,$imgfile,$cardnumber);
+    $sth->execute($cardnumber,$mimetype,$imgfile,$imgfile);
     warn "Error returned inserting $cardnumber.$mimetype." if $sth->errstr;
     my $dberror = $sth->errstr;
     $sth->finish;
     return $dberror;
 }
 
+=head2 RmPatronImage
+
+    my ($dberror) = RmPatronImage($cardnumber);
+
+Removes the image for the patron with the supplied cardnumber.
+
+=cut
+
+sub RmPatronImage {
+    my ($cardnumber) = @_;
+    warn "Cardnumber passed to GetPatronImage is $cardnumber" if $debug;
+    my $dbh = C4::Context->dbh;
+    my $query = "DELETE FROM patronimage WHERE cardnumber = ?;";
+    my $sth = $dbh->prepare($query);
+    $sth->execute($cardnumber);
+    my $dberror = $sth->errstr;
+    warn "Database error!" if $sth->errstr;
+    $sth->finish;
+    return $dberror;
+}
+
 =head2 GetRoadTypeDetails (OUEST-PROVENCE)
 
   ($roadtype) = &GetRoadTypeDetails($roadtypeid);
index 2108b58..c601bd8 100644 (file)
@@ -196,10 +196,16 @@ for (var i=0;i<ItemsNodes.length;i++){
 
 <div>
 <!-- TMPL_IF NAME="patronimages" -->
-       <!-- TMPL_IF NAME="CAN_user_tools" --><!-- TMPL_UNLESS NAME="picture" -->
+       <!-- TMPL_IF NAME="CAN_user_tools" -->
                <form method="post" action="/cgi-bin/koha/tools/picture-upload.pl" enctype="multipart/form-data">
-                <fieldset class="brief"><legend>Upload Patron Image</legend>
-                   <div class="hint"><!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> does not currently have an image available. To import an image for <!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="surname" -->, enter the name of an image file to upload.</div>
+                <!-- TMPL_IF NAME="picture" -->
+                    <fieldset class="brief"><legend>Manage Patron Image</legend>
+                        <div class="hint">To update the image for <!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="surname" -->, enter the name of the new image file to upload and click 'Upload.' <br />Click the 'Delete' button to remove the current image.</div>
+                <!-- /TMPL_IF -->
+                <!-- TMPL_UNLESS NAME="picture" -->
+                    <fieldset class="brief"><legend>Upload Patron Image</legend>
+                        <div class="hint"><!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> does not currently have an image available. To import an image for <!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="surname" -->, enter the name of an image file to upload.</div>
+                <!-- /TMPL_UNLESS -->
                    <input type="hidden" id="image" name="filetype" value="image" />
                    <input type="hidden" id="cardnumber" name="cardnumber" value="<!-- TMPL_VAR NAME="cardnumber" -->" />
                    <input type="hidden" id="borrowernumber" name="borrowernumber" value="<!-- TMPL_VAR NAME="borrowernumber" -->" />
@@ -208,11 +214,13 @@ for (var i=0;i<ItemsNodes.length;i++){
                            <label for="uploadfile">Select the file to upload: </label><input type="file" id="uploadfile" name="uploadfile" />
                          </li>
                     </ol>
-                    <fieldset class="action"><input type="submit" value="Upload" class="submit" />
+                    <fieldset class="action">
+                        <input name="op" type="submit" value="Upload" class="submit" />
+                        <!-- TMPL_IF NAME="picture" --><input name="op" type="submit" value="Delete" class="submit" /><!-- /TMPL_IF -->
+                    </fieldset>
                 </fieldset>
                 </form>
-<!-- /TMPL_UNLESS -->
-<!-- /TMPL_IF -->
+        <!-- /TMPL_IF -->
 <!-- /TMPL_IF -->
 </div>
 
index 2188794..190eb8d 100644 (file)
@@ -98,7 +98,9 @@
                        </ol>
                                        </li></ol>
                    </fieldset>
-                    <fieldset class="action"><input type="submit" value="Upload" class="submit" /> <a href="/cgi-bin/koha/tools/picture-upload.pl" class="cancel">Cancel</a>
+                    <fieldset class="action">
+                        <input type="submit" name="op" value="Upload" class="submit" />
+                        <input type="submit" name="op" value="Cancel" class="submit" />
                     </fieldset>
                 </form>
        
index 96e84ea..144ca78 100755 (executable)
@@ -46,6 +46,7 @@ my $cardnumber          = $input->param('cardnumber');
 my $uploadfilename      = $input->param('uploadfile');
 my $uploadfile          = $input->upload('uploadfile');
 my $borrowernumber      = $input->param('borrowernumber');
+my $op                  = $input->param('op');
 
 #FIXME: This code is really in the rough. The variables need to be re-scoped as the two subs depend on global vars to operate.
 #       Other parts of this code could be optimized as well, I think. Perhaps the file upload could be done with YUI's upload
@@ -67,11 +68,11 @@ THis script is called and presents the user with an interface allowing him/her t
 
 =cut
 
-
+warn "Operation requested: $op" if $DEBUG;
 
 my ( $total, $handled, @counts, $tempfile, $tfh );
 
-if ( $uploadfile ) {
+if ( ($op eq 'Upload') && $uploadfile ) {       # Case is important in these operational values as the template must use case to be visually pleasing!
     my $dirname = File::Temp::tempdir( CLEANUP => 1);
     warn "dirname = $dirname" if $DEBUG;
     my $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
@@ -132,13 +133,18 @@ if ( $uploadfile ) {
             );
         }   
     }
-} else {
-       $template->param(cardnumber => $cardnumber );
-       $template->param(filetype => $filetype );
+} elsif ( ($op eq 'Upload') && !$uploadfile ) {
+    warn "Problem uploading file or no file uploaded.";
+    $template->param(cardnumber => $cardnumber);
+    $template->param(filetype => $filetype);
+} elsif ( $op eq 'Delete' ) {
+    my $dberror = RmPatronImage($cardnumber);
+    warn "Database returned $dberror" if $dberror;
+} elsif ( $op eq 'Cancel' ) {
+    print $input->redirect ("/cgi-bin/koha/tools/picture-upload.pl");
 }
 
 if ( $borrowernumber && !$errors && !$template->param('ERRORS') ) {
-    my $urlbase = $input->url(-base => 1 -rewrite => 1);
     print $input->redirect ("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber");
 } else {
     output_html_with_http_headers $input, $cookie, $template->output;