added support for documents

if pdf creation failed, show the failed documents and added a button to force creation of the pdf and skip broken files
This commit is contained in:
Andreas Moik
2016-08-01 16:31:00 +02:00
parent 8074fa5383
commit 85d397b451
3 changed files with 99 additions and 31 deletions
+97 -30
View File
@@ -31,6 +31,8 @@ $p=new phrasen($sprache);
$db = new basis_db();
$errors = array();
$user = get_uid();
if(!isset($_GET["prestudent_ids"]) || !isset($_GET["vorlage_kurzbz"]))
@@ -41,7 +43,7 @@ $prestudent_ids = explode(";", $_GET["prestudent_ids"]);
if(count($prestudent_ids) < 1)
die($p->t('anwesenheitsliste/fehlerhafteParameteruebergabe'));
( isset($_GET["force"]) ? $force = true : $force = false);
/*
* Temporaeren Ordner fuer die erstellung der Dokumente generieren
@@ -66,7 +68,7 @@ foreach($prestudent_ids as $pid)
{
$prestudent = new prestudent();
if(!$prestudent->load($pid))
cleanUpAndDie($p->t('tools/studentWurdeNichtGefunden')."(".$pid.")", $tmpDir);
$errors[] = $p->t('tools/studentWurdeNichtGefunden')."(".$pid.")";
/*
@@ -74,7 +76,7 @@ foreach($prestudent_ids as $pid)
*/
$query= '
SELECT
titel, dms_id, inhalt
titel, dms_id, inhalt, mimetype
FROM
public.tbl_dokumentstudiengang
JOIN public.tbl_prestudent USING(studiengang_kz)
@@ -88,6 +90,7 @@ foreach($prestudent_ids as $pid)
$result = $db->db_query($query);
while($row = $db->db_fetch_object($result))
{
$convertSuccess = true;
$filename = "";
if($row->inhalt != null)
{
@@ -103,37 +106,77 @@ foreach($prestudent_ids as $pid)
$filename = DMS_PATH . $dms->filename;
}
// this should never happen
if($filename == "")
continue;
/*
* Determine the filetype
* and convert, if nessecary
* and convert if nessecary
*/
$fullFilename = "";
$explodedTitle = explode(".", $row->titel);
$type = $explodedTitle[count($explodedTitle)-1];
if($type == "jpg" || $type = "jpeg")
if(
$type == "jpg"
|| $type == "jpeg"
|| $row->mimetype == "image/jpeg"
|| $row->mimetype == "image/jpg"
|| $row->mimetype == "image/pjpeg"
)
{
$fullFilename = $tmpDir . "/".uniqid() . ".pdf";
if(!$pdf->jpegToPdf($filename, $fullFilename))
cleanUpAndDie($pdf->errormsg, $tmpDir);
}
else if($type == "odt" || $type == "doc" || $type == "docx")
else if
(
$type == "odt"
|| $type == "doc"
|| $type == "docx"
|| $row->mimetype == "application/vnd.oasis.opendocument.spreadsheet"
|| $row->mimetype == "application/msword"
|| $row->mimetype == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|| $row->mimetype == "application/haansoftdocx"
|| $row->mimetype == "application/vnd.ms-word"
|| $row->mimetype == "application/vnd.oasis.opendocument.text"
)
{
$fullFilename = $tmpDir . "/".uniqid() . ".pdf";
$docExp->convert($filename, $fullFilename, "pdf");
if(!$docExp->convert($filename, $fullFilename, "pdf"))
{
$convertSuccess = false;
$errors[] ="'$row->titel': Konvertierung fehlgeschlagen(".$row->mimetype.")";
}
}
else if($type == "pdf")
else if(
$type == "pdf"
|| $row->mimetype == "application/pdf"
)
{
$fullFilename = $row->titel;
$fullFilename = $filename;
}
// only filled, if the file is supported
if($fullFilename != "")
{
$preDocs[] = $fullFilename;
if(file_exists($fullFilename))
$preDocs[] = $fullFilename;
else
{
$addString = "";
if($row->dms_id)
$addString = "(DMS)";
else
$addString = "(DB)";
if($convertSuccess)
$errors[] = '"' . $row->titel . '":' . $addString . ' Dokument nicht gefunden';
}
}
else
$errors[] ="'$row->titel' hat einen nicht unterstützten mimetype: $row->mimetype";
}
/*
@@ -141,7 +184,7 @@ foreach($prestudent_ids as $pid)
*/
$filename = $tmpDir . "/".uniqid();
$doc = new dokument_export($_GET["vorlage_kurzbz"]);
$doc->addDataArray(array('vorname' => $prestudent->vorname, 'nachname' => $prestudent->nachname),"bewerberakt");
$doc->addDataArray(array('vorname' => $prestudent->vorname, 'nachname' => $prestudent->nachname),"dokumentenakt");
if(!$doc->create('pdf'))
die($doc->errormsg);
@@ -154,28 +197,52 @@ foreach($prestudent_ids as $pid)
unset($doc);
}
/*
* generate the merged PDF
*/
$finishedPdf = $tmpDir . "/Dokumentenakt.pdf";
if(!$pdf->merge($allDocs, $finishedPdf))
cleanUpAndDie($pdf->errormsg, $tmpDir);
$fsize = filesize($finishedPdf);
if(!$handle = fopen($finishedPdf,'r'))
die('load failed');
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="'.$finishedPdf);
header('Content-Length: '.$fsize);
while (!feof($handle))
if(count($errors) == 0 || $force)
{
echo fread($handle, 8192);
$finishedPdf = $tmpDir . "/Dokumentenakt.pdf";
if(!$pdf->merge($allDocs, $finishedPdf))
cleanUpAndDie($pdf->errormsg, $tmpDir);
$fsize = filesize($finishedPdf);
if(!$handle = fopen($finishedPdf,'r'))
die('load failed');
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="'.$finishedPdf);
header('Content-Length: '.$fsize);
while (!feof($handle))
{
echo fread($handle, 8192);
}
fclose($handle);
}
else
{
?>
<html>
<head></head>
<body>
<?php
echo "<h1>Es sind folgende Fehler aufgetreten:</h1>";
foreach($errors as $e)
{
echo "<p>$e</p>";
}
echo "<form action='dokumentenakt.pdf.php' method='GET'>";
echo '<input type="hidden" name="prestudent_ids" value="'.$_GET["prestudent_ids"].'"/>';
echo '<input type="hidden" name="vorlage_kurzbz" value="'.$_GET["vorlage_kurzbz"].'"/>';
echo '<input type="submit" name="force" value="Fortfahren" title="Fehlerhafte Dokumente auslassen"/>';
echo "</form>";
?>
</body>
</html>
<?php
}
fclose($handle);
/*
@@ -198,7 +265,7 @@ function cleanUpAndDie($msg, $tmpDir)
function removeFolder($dir)
{
return;
if($dir == "/")
return false;
if (is_dir($dir) === true)
+1
View File
@@ -34,6 +34,7 @@ class dokument_export
private $temp_filename;
private $temp_folder;
private $images=array();
public $errormsg;
/**
* Konstruktor
+1 -1
View File
@@ -5,7 +5,7 @@ xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn
>
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:template match="bewerberakt">
<xsl:template match="dokumentenakt">
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2"><office:scripts/><office:font-face-decls><style:font-face style:name="Liberation Serif" svg:font-family="&apos;Liberation Serif&apos;" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Liberation Sans" svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu Sans&apos;" style:font-family-generic="system" style:font-pitch="variable"/></office:font-face-decls><office:automatic-styles><style:style style:name="P1" style:family="paragraph" style:parent-style-name="Heading_20_1"><style:paragraph-properties fo:text-align="center" style:justify-single-word="false"/></style:style><style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard"><style:text-properties officeooo:rsid="0003bc74" officeooo:paragraph-rsid="0003bc74"/></style:style></office:automatic-styles><office:body><office:text><text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls><text:p text:style-name="Title">Bewerberakt</text:p><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:p text:style-name="P2"/><text:h text:style-name="P1" text:outline-level="1"><xsl:value-of select="vorname" /><xsl:text> </xsl:text><xsl:value-of select="nachname" /></text:h></office:text></office:body></office:document-content>