X-Git-Url: https://git.infodrom.org/?p=misc%2Fhallinta-metro;a=blobdiff_plain;f=utils.php;h=45b1c935a2a2da6c8c5f565cf6c00fc10784c69c;hp=f7c4729cf4d5d044347c896f27d95df406a2eb22;hb=44602f0fd181b7789ba4c5289d5dd4bc2526c7b1;hpb=9e4ea92475f6f1fbaf0e39cf0f093bd1812cdf25 diff --git a/utils.php b/utils.php index f7c4729..45b1c93 100644 --- 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() { @@ -22,11 +34,26 @@ function rm_tempdir($dir) system(sprintf("rm -rf %s", $dir)); } +function latexspecialchars($string) +{ + $map = array( + "#"=>"\\#", + "$"=>"\\$", + "%"=>"\\%", + "&"=>"\\&", + "~"=>"\\~{}", + "_"=>"\\_", + "^"=>"\\^{}", + "\\"=>"\\textbackslash", + "{"=>"\\{", + "}"=>"\\}", + ); + return preg_replace("/([\^\%~\\\\#\$%&_\{\}])/e", "\$map['$1']", $string); +} + function latex_encode($text) { - return str_replace(array("\\",'%'), - array('\\','\%'), - utf8_decode($text)); + return latexspecialchars(utf8_decode($text)); } function ordersatz_archive($id, $title, $filename) @@ -126,13 +153,13 @@ function ordersatz_write($id, $dir, $send) fwrite($f, sprintf('\newcommand{\datum}{%d.%d.%d}'."\n", $d[2], $d[1], $d[0])); fclose($f); - $sql = sprintf("SELECT artnr,gang,metro_vpe.short AS vpname,menge,bezeichnung,hersteller,anzahl " . + $sql = sprintf("SELECT artnr,gang,metro_vpe.short AS vpname,menge,bezeichnung,hinweis,hersteller,anzahl " . "FROM metro_ordersatz_pos " . "JOIN metro_artikel ON artikel = metro_artikel.id " . "JOIN metro_abteilung ON abteilung = metro_abteilung.id " . "JOIN metro_vpe ON vpe = metro_vpe.id " . "WHERE ordersatz = %d AND anzahl IS NOT NULL " . - "ORDER BY gang,metro_abteilung.name", + "ORDER BY gang,metro_abteilung.name,bezeichnung", $id); $result = query_db($sql); @@ -143,24 +170,36 @@ function ordersatz_write($id, $dir, $send) $f = fopen(FNAME_ITEMS, 'w'); foreach ($result as $row) { - $bez = $row['bezeichnung']; + $bez = latex_encode($row['bezeichnung']); if (strlen($row['hersteller'])) - $bez .= ' (' . $row['hersteller'] . ')'; + $bez .= ' (' . latex_encode($row['hersteller']) . ')'; + if (strlen($row['hinweis'])) + $bez .= sprintf("\\newline\\textbf{%s}", latex_encode($row['hinweis'])); - fwrite($f, sprintf('\order{%d}{%d}{%s %s}{%s}'."\n", + fwrite($f, sprintf('\order{%d}{%s}{%s %s}{%s}{%s}'."\n", $row['anzahl'], - $row['artnr'], - $row['menge'], - latex_encode($bez), - latex_encode($row['vpname']))); + $row['artnr'] ? (int)$row['artnr'] : '', + latex_encode($row['menge']), + $bez, + latex_encode($row['vpname']), + latex_encode($row['gang']))); } 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"; @@ -185,9 +224,9 @@ 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'], + mb_encode_mimeheader(utf8_decode('Infodrom ' . $satz[0]['koch']),'latin1'), array($dir . '/ordersatz.pdf'), $message); @@ -197,4 +236,4 @@ function ordersatz_write($id, $dir, $send) return true; } -?> \ No newline at end of file +?>