PDF documents sent by email have now meaningful names.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 29 Aug 2015 09:32:32 +0000 (11:32 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 29 Aug 2015 09:32:32 +0000 (11:32 +0200)
reporting/includes/class.mail.inc
reporting/includes/pdf_report.inc

index 7cce85a109e1788546d2c2d4cc265bad504162e2..26a109fdadd2c0f66e898f4b3a249c2eb19e24e9 100644 (file)
@@ -65,9 +65,11 @@ class email
        $this->bcc[] = $mail;
     }
 
-    function attachment($file)
+    function attachment($file, $filename=null)
     {
-               $this->attachment[] = $file;
+       if (!isset($filename))
+               $filename = basename($file);
+                       $this->attachment[$filename] = $file;
     }
 
     function subject($subject)
@@ -130,12 +132,13 @@ class email
         if ($max > 0)
         {
             for ($i = 0; $i < $max; $i++)
+            foreach ($this->attachment as $filename => $file)
             {
-                $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
+                $file = fread(fopen($file, "r"), filesize($file));
                                $this->body .= "--".$this->boundary."\n";
-                               $this->body .= "Content-Type: " .$this->mime_type(basename($this->attachment[$i])). "; name=\"".basename($this->attachment[$i])."\"\n";
+                               $this->body .= "Content-Type: " .$this->mime_type($file). "; name=\"".$filename."\"\n";
                                $this->body .= "Content-Transfer-Encoding: base64\n";
-                               $this->body .= "Content-Disposition: attachment; filename=\"".basename($this->attachment[$i])."\"\n\n";
+                               $this->body .= "Content-Disposition: attachment; filename=\"".$filename."\"\n\n";
                                $this->body .= chunk_split(base64_encode($file),"72","\n");
                 $file = "";
             }
index c8bd32550b1204d028fdf0305cf1ff34b2af6c35..9e96bf2ca826169e461f1a3b8914d6650d83f913 100644 (file)
@@ -969,10 +969,10 @@ class FrontReport extends Cpdf
                        }
                        // do not use standard filenames or your sensitive company data 
                        // are world readable
-                       if ($email == 1)
-                               $fname = $dir.'/'.$this->filename;
-                       else    
-                               $fname = $dir.'/'.uniqid('').'.pdf';
+//                     if ($email == 1)
+//                             $fname = $dir.'/'.$this->filename;
+//                     else    
+                       $fname = $dir.'/'.uniqid('').'.pdf';
                        $this->Output($fname, 'F');
 
                        if ($email == 1)
@@ -1026,7 +1026,7 @@ class FrontReport extends Cpdf
                                        $mail->to($to); $try++;
                                        $mail->subject($subject);
                                        $mail->text($msg . $sender);
-                                       $mail->attachment($fname);
+                                       $mail->attachment($fname, $this->filename);
                                        $emails .= " " . $contact['email'];
                                        if ($mail->send()) $sent++;
                                        } // foreach contact