Adjust to new framework
[misc/hallinta-metro] / utils.php
index 016f15b..45b1c93 100644 (file)
--- a/utils.php
+++ b/utils.php
@@ -5,6 +5,18 @@ define('TEMPLATE', 'ordersatz.tex');
 define('FNAME_VARS', 'ordersatz_vars.tex');
 define('FNAME_ITEMS', 'ordersatz_items.tex');
 define('FAXNUMBER','2002-364');
+define('ERROR_SAFT','joey@finlandia');
+define('ERROR_MAIL','joey@finlandia.infodrom.org');
+
+function is_done($id)
+{
+  global $db;
+
+  $query = sprintf('SELECT count(*) AS count FROM metro_ordersatz WHERE id = %d AND done IS NULL', $id);
+  $sth = $db->query($query);
+  $row = $sth->fetch();
+  return $row['count'] == 0;
+}
 
 function mk_tempdir()
 {
@@ -175,10 +187,19 @@ function ordersatz_write($id, $dir, $send)
 
   fclose($f);
 
-  system("latex ordersatz > ordersatz.out 2>&1 && dvips ordersatz >> ordersatz.out 2>&1 && ps2pdf ordersatz.ps", $ret);
+  system("latex ordersatz > ordersatz.out 2>&1 && dvips ordersatz >> ordersatz.out 2>&1 && pdflatex ordersatz >> ordersatz.out", $ret);
 
-  if ($ret !== 0)
+  if ($ret !== 0) {
+    $fname = sprintf("ordersatz-%d-%d.tar.bz2", $id, time());
+    $cmd = sprintf("tar cfj %s ordersatz.tex ordersatz_vars.tex ordersatz_items.tex ordersatz.out && " .
+                  "mpack -s 'Probleme beim Compilieren des Ordersatzes %d' -d ordersatz.out %s %s && " .
+                  "sendfile -Q -c='Probleme beim Compilieren des Ordersatzes %d' %s %s",
+                  $fname,
+                  $id, $fname, ERROR_MAIL,
+                  $id, $fname, ERROR_SAFT);
+    system($cmd);
     return "Probleme beim Compilieren des Ordersatzes";
+  }
 
   if (!file_exists('ordersatz.ps'))
     return "Postscript-Datei nicht erstellt";