Encode subject properly so that foreign characters are transmitted properly
[misc/hallinta-metro] / utils.php
index 9f9261f..d6905e9 100644 (file)
--- a/utils.php
+++ b/utils.php
@@ -137,6 +137,9 @@ function ordersatz_write($id, $dir, $send)
 
   $result = query_db($sql);
 
+  if (count($result) == 0)
+    return "Keine Artikel zur Bestellung ausgewählt";
+
   $f = fopen(FNAME_ITEMS, 'w');
 
   foreach ($result as $row) {
@@ -144,9 +147,9 @@ function ordersatz_write($id, $dir, $send)
     if (strlen($row['hersteller']))
       $bez .= ' (' . $row['hersteller'] . ')';
 
-    fwrite($f, sprintf('\order{%d}{%d}{%s %s}{%s}'."\n",
+    fwrite($f, sprintf('\order{%d}{%s}{%s %s}{%s}'."\n",
                       $row['anzahl'],
-                      $row['artnr'],
+                      $row['artnr'] ? (int)$row['artnr'] : '',
                       $row['menge'],
                       latex_encode($bez),
                       latex_encode($row['vpname'])));
@@ -168,6 +171,9 @@ function ordersatz_write($id, $dir, $send)
     if ($ret !== true)
       return $ret;
 
+    if (empty($satz[0]['email']))
+      $satz[0]['email'] = 'joey@infodrom.org';
+
     $cmd = sprintf("faxspool -f %s %s %s > /dev/null 2>&1",
                   $satz[0]['email'],
                   FAXNUMBER,
@@ -179,7 +185,7 @@ function ordersatz_write($id, $dir, $send)
                       $satz[0]['koch']);
 
     mail_attach($satz[0]['email'],
-               'Ordersatz ' . $satz[0]['name'],
+               mb_encode_mimeheader(utf8_decode('Ordersatz ' . $satz[0]['name']),'latin1'),
                $satz[0]['email'],
                'Infodrom ' . $satz[0]['koch'],
                array($dir . '/ordersatz.pdf'),