Dokumentenakt

This commit is contained in:
Andreas Moik
2016-07-27 17:18:38 +02:00
parent 4edc917b3d
commit 6d0f5d2bec
6 changed files with 400 additions and 1 deletions
+218
View File
@@ -0,0 +1,218 @@
<?php
/* Copyright (C) 2016 Technikum-Wien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Andreas Moik <moik@technikum-wien.at>.
*/
require_once(dirname(__FILE__).'/../config/vilesci.config.inc.php');
require_once(dirname(__FILE__).'/../include/pdf.class.php');
require_once(dirname(__FILE__).'/../include/dokument_export.class.php');
require_once(dirname(__FILE__).'/../include/phrasen.class.php');
require_once(dirname(__FILE__).'/../include/prestudent.class.php');
require_once(dirname(__FILE__).'/../include/dms.class.php');
$sprache = getSprache();
$p=new phrasen($sprache);
$db = new basis_db();
$user = get_uid();
if(!isset($_GET["prestudent_ids"]) || !isset($_GET["vorlage_kurzbz"]))
die($p->t('anwesenheitsliste/fehlerhafteParameteruebergabe'));
$prestudent_ids = explode(";", $_GET["prestudent_ids"]);
if(count($prestudent_ids) < 1)
die($p->t('anwesenheitsliste/fehlerhafteParameteruebergabe'));
/*
* Temporaeren Ordner fuer die erstellung der Dokumente generieren
*/
$tmpDir = sys_get_temp_dir() . "/dokumentenakt_" . uniqid();
if (!file_exists($tmpDir))
mkdir($tmpDir, 0777, true);
/*
* converter classes
*/
$pdf = new pdf();
$docExp = new dokument_export();
/*
* Create Documents
*/
$allDocs = array();
foreach($prestudent_ids as $pid)
{
$prestudent = new prestudent();
if(!$prestudent->load($pid))
cleanUpAndDie($p->t('tools/studentWurdeNichtGefunden')."(".$pid.")", $tmpDir);
/*
* Deckblatt
*/
$filename = $tmpDir . "/".uniqid();
$doc = new dokument_export('Bewerberakt');
$doc->addDataArray(array('vorname' => $prestudent->vorname, 'nachname' => $prestudent->nachname),'bewerberakt');
if(!$doc->create('pdf'))
die($doc->errormsg);
$doc->temp_filename = $filename;
$doc->output(false);
//$doc->close();
$allDocs[] = $filename;
/*
* Get all Documents
*/
$query= '
SELECT
titel, dms_id, inhalt
FROM
public.tbl_dokumentstudiengang
JOIN public.tbl_prestudent USING(studiengang_kz)
JOIN public.tbl_akte USING(person_id,dokument_kurzbz)
WHERE
onlinebewerbung
AND prestudent_id='.$db->db_add_param($pid, FHC_INTEGER).';
';
$result = $db->db_query($query);
while($row = $db->db_fetch_object($result))
{
$filename = "";
if($row->dms_id != null)
{
$dms = new dms();
$dms->load($row->dms_id);
$filename = DMS_PATH . $dms->filename;
}
else if($row->inhalt != null)
{
$filename = $tmpDir . "/".uniqid();
$fileData = base64_decode($row->inhalt);
file_put_contents($filename, $fileData);
}
if($filename == "")
continue;
/*
* Determine the filetype
* and convert, if nessecary
*/
$explodedTitle = explode(".", $row->titel);
$type = $explodedTitle[count($explodedTitle)-1];
if($type == "jpg" || $type = "jpeg")
{
$fullFilename = $tmpDir . "/".uniqid() . ".pdf";
if(!$pdf->jpegToPdf($filename, $fullFilename))
cleanUpAndDie($pdf->errormsg, $tmpDir);
}
else if($type == "odt" || $type == "doc" || $type == "docx")
{
$fullFilename = $tmpDir . "/".uniqid() . ".pdf";
$docExp->convert($filename, $fullFilename, "pdf");
}
else if($type == "pdf")
{
$fullFilename = $row->titel;
}
else
cleanUpAndDie("falscher typ TODO", $tmpDir);
// only filled, if the file is supported
if($fullFilename != "")
{
$allDocs[] = $fullFilename;
}
}
}
/*
* 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))
{
echo fread($handle, 8192);
}
fclose($handle);
/*
* Cleanup
*/
removeFolder($tmpDir);
/*
* Functions
*/
function cleanUpAndDie($msg, $tmpDir)
{
removeFolder($tmpDir);
die($msg);
}
function removeFolder($dir)
{
if($dir == "/")
return false;
if (is_dir($dir) === true)
{
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file)
{
unlink($dir . "/" . $file);
}
return rmdir($dir);
}
return false;
}
?>
+28 -1
View File
@@ -16,6 +16,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* *
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and * Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
* Andreas Moik <moik@technikum-wien.at>.
*/ */
require_once(dirname(__FILE__).'/vorlage.class.php'); require_once(dirname(__FILE__).'/vorlage.class.php');
require_once(dirname(__FILE__).'/addon.class.php'); require_once(dirname(__FILE__).'/addon.class.php');
@@ -37,8 +38,11 @@ class dokument_export
/** /**
* Konstruktor * Konstruktor
*/ */
public function __construct($vorlage, $oe_kurzbz=0, $version=null) public function __construct($vorlage = null, $oe_kurzbz=0, $version=null)
{ {
if(!isset($vorlage))
return;
//Vorlage aus der Datenbank holen //Vorlage aus der Datenbank holen
$this->vorlage = new vorlage(); $this->vorlage = new vorlage();
if(!$this->vorlage->getAktuelleVorlage($oe_kurzbz, $vorlage, $version)) if(!$this->vorlage->getAktuelleVorlage($oe_kurzbz, $vorlage, $version))
@@ -389,5 +393,28 @@ class dokument_export
} }
return $_xml_data->asXML(); return $_xml_data->asXML();
} }
/**
* Konvertiert ein Dokument in ein anderes Format
* @param string $inFile Origin File Path
* @param string $outFile Output file
* @param string $format Format to export To
* @return boolean
*/
public function convert($inFile, $outFile, $format = "pdf")
{
$command = 'unoconv --format %s --output %s %s';
$command = sprintf($command, $format, $outFile, $inFile);
exec($command, $out, $ret);
if($ret!=0)
{
$this->errormsg = 'Dokumentenkonvertierung ist derzeit nicht möglich. Bitte informieren Sie den Administrator';
return false;
}
return true;
}
} }
?> ?>
+107
View File
@@ -0,0 +1,107 @@
<?php
/* Copyright (C) 2016 fhcomplete.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Andreas Moik <moik@technikum-wien.at>.
*/
class Pdf
{
public $errormsg = "";
/**
* Fügt beliebig viele PDF Dateien zu einer zusammen
* @param array $files Array mit Dateien
* @param string $outFile Zieldatei
* @return boolean
*/
public function merge($files, $outFile)
{
$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outFile ";
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// add all pdf files to the command
foreach($files as $f)
{
$cmd .= $f." ";
if(!file_exists($f))
{
$this->errormsg = "File not found: '$f'";
return false;
}
if(finfo_file($finfo, $f) != "application/pdf")
{
$this->errormsg = "Wrong format: '$f'";
return false;
}
}
finfo_close($finfo);
exec($cmd, $out, $ret);
if($ret!=0)
{
$this->errormsg = 'PDF-zusammenfuegung ist derzeit nicht möglich. Bitte informieren Sie den Administrator';
return false;
}
return true;
}
/**
* Konvertiert eine jpeg Datei zu einer PDF
* @param string $image jpeg Datei
* @param string $outFile Zieldatei
* @return boolean
*/
public function jpegToPdf($image, $outFile)
{
if(!file_exists($image))
{
$this->errormsg = "File not found: '$image'";
return false;
}
$s = getimagesize($image);
/*
* längere Seite ermitteln
* Hochformat wenn die Seiten gleich lang sind.
*/
if($s[0] > $s[1])
{
$height = 595;
$width = 842;
}
else
{
$height = 842;
$width = 595;
}
// -r300 = 300 ppi
$cmd = 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -r100 -o '.$outFile.' viewjpeg.ps -c "('.$image.') << /PageSize [' . $width . ' ' . $height .'] /.HWMargins [18 18 18 13.5] /countspaces { [ exch { dup 32 ne { pop } if } forall ] length } bind def >> setpagedevice viewJPEG"';
exec($cmd, $out, $ret);
if($ret!=0)
{
$this->errormsg = 'jpegToPdf ist derzeit nicht möglich. Bitte informieren Sie den Administrator';
return false;
}
return true;
}
}
+33
View File
@@ -1297,6 +1297,39 @@ if(!@$db->db_query("SELECT bezeichnung_mehrsprachig FROM public.tbl_status LIMIT
} }
/************************************ 07.16 Vorlage für bewerberakt ************************************/
if($result = $db->db_query("SELECT * FROM public.tbl_vorlage WHERE vorlage_kurzbz='Bewerberakt'"))
{
if($db->db_num_rows($result)==0)
{
$qry_oe = "SELECT oe_kurzbz FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz is null";
if($result = $db->db_query($qry_oe))
{
$qry = "INSERT INTO public.tbl_vorlage(vorlage_kurzbz, bezeichnung, anmerkung,mimetype)
VALUES('Bewerberakt','Bewerberakt Deckblatt', 'wird als Deckblatt fuer den Bewerberakt verwendet', 'application/vnd.oasis.opendocument.text');";
$text = file_get_contents('xsl/Bewerberakt.xsl');
while($row = $db->db_fetch_object($result))
{
$qry.="INSERT INTO public.tbl_vorlagestudiengang(vorlage_kurzbz, studiengang_kz, version, text,
oe_kurzbz, style, berechtigung, anmerkung_vorlagestudiengang, aktiv) VALUES(
'Bewerberakt',0,0,".$db->db_add_param($text).",".$db->db_add_param($row->oe_kurzbz).",null,null,'',true);";
}
}
if(!$db->db_query($qry))
echo '<strong>Bewerberakt Dokumentenvorlage: '.$db->db_last_error().'</strong><br>';
else
echo 'Bewerberakt Dokumentenvorlage hinzugefuegt<br>';
}
}
// *** Pruefung und hinzufuegen der neuen Attribute und Tabellen // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen
echo '<H2>Pruefe Tabellen und Attribute!</H2>'; echo '<H2>Pruefe Tabellen und Attribute!</H2>';
Binary file not shown.
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
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"
>
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:template match="bewerberakt">
<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:value-of select="nachname" /></text:h></office:text></office:body></office:document-content>
</xsl:template>
</xsl:stylesheet>