[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[3612] trunk



Revision: 3612
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3612&view=rev
Author:   einhverfr
Date:     2011-08-02 21:37:38 +0000 (Tue, 02 Aug 2011)

Log Message:
-----------
file attachment now saves data to db, but errors after commit, during redirect.  Also does not display.

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject.pm
    trunk/LedgerSMB/File.pm
    trunk/UI/file/attachment_screen.html
    trunk/UI/journal/journal_entry.html
    trunk/scripts/file.pl
    trunk/sql/modules/Files.sql

Modified: trunk/LedgerSMB/DBObject.pm
===================================================================
--- trunk/LedgerSMB/DBObject.pm	2011-08-02 17:06:04 UTC (rev 3611)
+++ trunk/LedgerSMB/DBObject.pm	2011-08-02 21:37:38 UTC (rev 3612)
@@ -144,7 +144,7 @@
     }
     $ref->{pronargs} = 0 unless defined $ref->{pronargs};
     # If the user provided args..
-    if (!defined  $args{args}) {
+    if (!defined $args{args}) {
         @proc_args = $self->_parse_array($pargs);
         if (@proc_args) {
             for my $arg (@proc_args) {
@@ -157,7 +157,7 @@
                      else
                      {
                         $logger->debug("exec_method pushing \$arg defined $arg | \$self->{\$arg} is undefined");
-                        $self->{$arg} = undef;
+                        #$self->{$arg} = undef; # Why was this being unset? --CT
                      }
                      push ( @call_args, $self->{$arg} );
                 }

Modified: trunk/LedgerSMB/File.pm
===================================================================
--- trunk/LedgerSMB/File.pm	2011-08-02 17:06:04 UTC (rev 3611)
+++ trunk/LedgerSMB/File.pm	2011-08-02 21:37:38 UTC (rev 3612)
@@ -20,7 +20,7 @@
 use Class::Struct;
 use LedgerSMB::DBObject;
 use File::MimeInfo;
-use IO::Scalar;
+#use IO::Scalar;
 use strict;
 
 =item  attached_by_id
@@ -209,16 +209,15 @@
 
 sub get_mime_type {
     my ($self) = @_;
-    if ($self->mime_type_text){
-       return $self->mime_type_text;
-    } else {
-       my ($ref) = $self->exec_method(
-                      {funcname => 'file__mime_type_text',
-                       args     => [$self->mime_type_id, undef]},
-       );
+    if (!($self->mime_type_id || $self->mime_type_text)){
+       $self->mime_type_text(mimetype($self->file_name));
+    } 
+    if (!($self->mime_type_id && $self->mime_type_text)){
+       my ($ref) = $self->exec_method({funcname => 'file__get_mime_type'});
        $self->mime_type_text($ref->{mime_type});
-       return $self->mime_type_text;
-    }
+       $self->mime_type_id($ref->{id});
+    } 
+    return $self->mime_type_text;
 }
 
 =item set_mime_type
@@ -299,7 +298,7 @@
 
 sub exec_method{
     my ($self, $args) = @_;
-    if (!scalar @{$args->{args}}){
+    if (!$args->{args}){
           $self->dbobject->{attached_by_id} = $self->attached_by_id;
           $self->dbobject->{attached_by}    = $self->attached_by;
           $self->dbobject->{attached_at}    = $self->attached_at;

Modified: trunk/UI/file/attachment_screen.html
===================================================================
--- trunk/UI/file/attachment_screen.html	2011-08-02 17:06:04 UTC (rev 3611)
+++ trunk/UI/file/attachment_screen.html	2011-08-02 21:37:38 UTC (rev 3612)
@@ -3,7 +3,17 @@
 ?>
 <?lsmb PROCESS 'elements.html' ?>
 
-<form action="recon.pl" method="post" enctype="multipart/form-data">
+<form action="file.pl" method="post" enctype="multipart/form-data">
+    <?lsmb INCLUDE input element_data = {
+            type = "hidden"
+           value = file_class
+            name = "file_class"
+    } ?>
+    <?lsmb INCLUDE input element_data = {
+            type = "hidden"
+           value = ref_key
+            name = "ref_key"
+    } ?>
 <div class="listtop" id="title"><?lsmb text('Attach File') ?></div>
 <div class="inputline">
     <div class="inputgroup">

Modified: trunk/UI/journal/journal_entry.html
===================================================================
--- trunk/UI/journal/journal_entry.html	2011-08-02 17:06:04 UTC (rev 3611)
+++ trunk/UI/journal/journal_entry.html	2011-08-02 21:37:38 UTC (rev 3612)
@@ -347,8 +347,8 @@
 </tr>
 <?lsmb END # FOREACH ?>
 </table>
-<a href="file.pl?action=show_attachment_screen&attach_to=<?lsmb form.id 
-   ?>">[<?lsmb text('Attach') ?>]</a>
+<a href="file.pl?action=show_attachment_screen&ref_key=<?lsmb form.id 
+   ?>&file_class=1">[<?lsmb text('Attach') ?>]</a>
 <?lsmb END # IF form.id ?>
 </form>
 </body>

Modified: trunk/scripts/file.pl
===================================================================
--- trunk/scripts/file.pl	2011-08-02 17:06:04 UTC (rev 3611)
+++ trunk/scripts/file.pl	2011-08-02 21:37:38 UTC (rev 3612)
@@ -21,6 +21,9 @@
 =cut
 
 package LedgerSMB::Scripts::file;
+use LedgerSMB::File;
+use LedgerSMB::File::Transaction;
+use LedgerSMB::File::Order;
 use strict;
 use CGI::Simple;
 
@@ -66,16 +69,30 @@
     $template->render($request);
 }
 
-=item attach
+=item attach_file
 
 Attaches a file to an object
         
 =cut
 
-sub attach {
+sub attach_file {
     my ($request) = @_;
-    my $file = $fileclassmap->{$request->{file_class}}->new;
+    my $file = $fileclassmap->{$request->{file_class}}->new();
+    $file->dbobject(LedgerSMB::DBObject->new({base => $request}));
+    my @fnames =  $request->{_request}->upload_info;
+    $file->file_name($fnames[0]);
     $file->merge($request);
+    if ($request->{url}){
+	$file->mime_type_text('text/x-uri');
+        $file->content($request->{url});
+    } else {
+        use File::MimeInfo;
+        $file->file_name($fnames[0]);
+        $file->get_mime_type;
+        my $fh = $request->{_request}->upload('upload_data');
+        my $fdata = join ("\n", <$fh>);
+        $file->content($fdata);
+    }
     $file->attach;
     my $cgi = LedgerSMB::CGI->new;
     print $cgi->redirect($request->{callback});

Modified: trunk/sql/modules/Files.sql
===================================================================
--- trunk/sql/modules/Files.sql	2011-08-02 17:06:04 UTC (rev 3611)
+++ trunk/sql/modules/Files.sql	2011-08-02 21:37:38 UTC (rev 3612)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION file__get_mime_type
- (in_mime_type_id int, in_mime_type text)
+ (in_mime_type_id int, in_mime_type_text text)
 RETURNS mime_type AS
 $$
 select * from mime_type 
@@ -32,7 +32,7 @@
        INSERT INTO file_transaction 
                    (content, mime_type_id, file_name, description, ref_key,
                    file_class, uploaded_by, uploaded_at)
-            VALUES (in_content, in_mime_type_id, in_file_name, in_description.
+            VALUES (in_content, in_mime_type_id, in_file_name, in_description,
                    in_ref_key, in_file_class, person__get_my_entity_id(), 
                    now());
         SELECT * INTO retval FROM file_base 
@@ -81,7 +81,7 @@
        INSERT INTO file_transaction 
                    (content, mime_type_id, file_name, description, ref_key,
                    file_class, uploaded_by, uploaded_at)
-            VALUES (in_content, in_mime_type_id, in_file_name, in_description.
+            VALUES (in_content, in_mime_type_id, in_file_name, in_description,
                    in_ref_key, in_file_class, person__get_my_entity_id(), 
                    now());
         SELECT * INTO retval FROM file_base 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.