require_once("../init.php");
require_once("loginfunctions.php");
require_once(dirname(__FILE__).'/../html2pdf/vendor/autoload.php');
include("../QuickTemplate.class");
require_once("uploadScreenshotFunctionsTest.php");
$versammlungid = $_GET["versammlungid"];
$gebietid = $_GET["gebietid"];
$templateid = $_GET["templateid"];
if (!isSessionLoggedOn() || !isSessionUserAllowedToSeeKingdomhall($versammlungid, $linki)) // is not logged on
{
header('HTTP/1.1 401 Unauthorized');
header('Location: forbidden.html');
}
else
{
$query = "SELECT * FROM gebiet_karten_vorlagen WHERE versammlungid = $versammlungid and id = $templateid";
$result = mysqli_query($linki, $query) or die('Error');
$templateFile = "";
$format = "";
$orientation = "";
$flipimagefront = "";
$flipimageback = "";
$hastplnotvisitBoolean = false;
if(mysqli_num_rows($result))
{
if($gebietkarten = mysqli_fetch_array($result))
{
extract($gebietkarten);
$templateFile = $templatefile;
$format = $format;
$orientation = $orientation;
$flipimagefront = $flipimagefront;
$flipimageback = $flipimageback;
if ($hastplnotvisit == "J")
$hastplnotvisitBoolean = true;
else
$hastplnotvisitBoolean = false;
}
}
//echo "STUZI " . $templateFile . " " . $format;
//exit;
$sessid = session_id();
$dirTemp = "screenshotsGebiete/tmp/";
$imfront = getScreenshotImage($versammlungid, $gebietid, "front", $linki);
$imback = getScreenshotImage($versammlungid, $gebietid, "back", $linki);
$tpl = new QuickTemplate("gktemplates/" . $templateFile);
$tplContent = file_get_contents("gktemplates/" . $templateFile);
$filefront = null;
if ($imfront != null)
{
$filefront = "sc-$gebietid-front-$sessid.png";
if ($flipimagefront == "H") imageflip ($imfront, IMG_FLIP_HORIZONTAL);
if ($flipimagefront == "V") imageflip ($imfront, IMG_FLIP_VERTICAL);
if ($flipimagefront == "VH") imageflip ($imfront, IMG_FLIP_BOTH);
imagepng($imfront, "./$dirTemp" . $filefront, 0);
imagedestroy($imfront);
//$tpl->AssignLocal("main", "URLSCREENSHOTFRONT", "
");
$tpl->AssignLocal("main", "URLSCREENSHOTFRONT", "./$dirTemp" . $filefront ."");
}
else
{
$tpl->AssignLocal("main", "URLSCREENSHOTFRONT", "./emptyscreenshot.png");
}
$fileback = null;
if ($imback != null)
{
$fileback = "sc-$gebietid-back-$sessid.png";
if ($flipimageback == "H") imageflip ($imback, IMG_FLIP_HORIZONTAL);
if ($flipimageback == "V") imageflip ($imback, IMG_FLIP_VERTICAL);
if ($flipimageback == "VH") imageflip ($imback, IMG_FLIP_BOTH);
imagepng($imback, "./$dirTemp" . $fileback, 0);
imagedestroy($imback);
// $tpl->AssignLocal("main", "URLSCREENSHOTBACK", "
");
$tpl->AssignLocal("main", "URLSCREENSHOTBACK", "./$dirTemp" . $fileback ."");
}
else
{
$tpl->AssignLocal("main", "URLSCREENSHOTBACK", "./emptyscreenshot.png");
}
$queryRegion = "select i.*, i.infotext as gebietname, DATE_FORMAT(i.ausgabedatum, '%d.%m.%Y') as ausgabedatumformatiert, DATE_FORMAT(DATE_ADD(i.ausgabedatum,INTERVAL 30*6 DAY), '%d.%m.%Y') as rueckgabedatumformatiert from v_gebieteinfos4benutzer i where versammlungid = $versammlungid and gebietid = $gebietid";
$result = mysqli_query($linki, $queryRegion) or die('Error Region');
if(mysqli_num_rows($result))
{
if($gebiet = mysqli_fetch_array($result))
{
extract($gebiet);
$tpl->AssignLocal("main", "REGIONNUMBER", "$customergebietnr");
$tpl->AssignLocal("main", "REGIONNAME", utf8_encode_if($gebietname));
$tpl->AssignLocal("main", "REGIONREGION", utf8_encode_if($region));
$tpl->AssignLocal("main", "REGIONOWNERVORNAME", utf8_encode_if($vorname));
$tpl->AssignLocal("main", "REGIONOWNERNACHNAME", utf8_encode_if($nachname));
$tpl->AssignLocal("main", "REGIONDATEGIVEAWAY", "$ausgabedatumformatiert");
// $rueckgabedatum = $ausgabedatum + 30*6;
$tpl->AssignLocal("main", "REGIONDATEGIVEBACK", "$rueckgabedatumformatiert");
$tpl->AssignLocal("main", "REGIONCOUNTWE", "$wohneinheiten");
}
}
$tpl->AssignLocal("main", "ACTDATE", date("d.m.Y H:i"));
$queryRegionNote = "select i.* from v_gebietenotizinfos i where versammlungid = $versammlungid and gebietid = $gebietid";
$resultNote = mysqli_query($linki, $queryRegionNote) or die('Error Note');
if(mysqli_num_rows($resultNote))
{
if($note = mysqli_fetch_array($resultNote))
{
extract($note);
$tpl->AssignLocal("main", "REGIONNOTE", preg_replace("/\r\n|\r|\n/",'
',utf8_encode_if($notiz)));
}
}
if ($hastplnotvisitBoolean) // Nicht besuchen
{
$hasNotVisitAll = false;
$tplBlockNotVisit = "main.NOTVISIT";
if (strpos($tplContent, "NOTVISITALL") !== false)
{
$hasNotVisitAll = true;
$tplBlockNotVisit = "main.NOTVISITALL.NOTVISIT";
}
$queryNB = "select i.*, DATE_FORMAT(i.modate, '%d.%m.%Y') as modateformatiert from v_gebiet_nichtbesuchen i where versammlungid = $versammlungid and gebietid = $gebietid";
$resultNB = mysqli_query($linki, $queryNB) or die('Error NB');
if(mysqli_num_rows($resultNB))
{
while($nichtb = mysqli_fetch_array($resultNB))
{
extract($nichtb);
try
{
$tpl->AssignLocal($tplBlockNotVisit, "NOTVISITNAME", utf8_encode_if($name));
$tpl->AssignLocal($tplBlockNotVisit, "NOTVISITADRESS", utf8_encode_if($adresse));
$tpl->AssignLocal($tplBlockNotVisit, "NOTVISITCOMMENT", utf8_encode_if($kommentar));
$tpl->AssignLocal($tplBlockNotVisit, "NOTVISITDATE", utf8_encode_if($modateformatiert));
$tpl->parse($tplBlockNotVisit);
}
catch (Exception $e)
{
//Kein Block vorhanden
}
}
if ($hasNotVisitAll)
{
$tpl->parse("main.NOTVISITALL");
}
}
}
//$tpl->AssignLocal("main", "URLSCREENSHOTFRONT", "./uploadScreenshotDownload.php?versammlungid=4&gebietid=261&side=front&type=jpeg");
//$tpl->AssignLocal("main", "URLSCREENSHOTFRONT", "./$dirTemp/sc-261-front.png");
// $tpl->AssignLocal("main", "URLSCREENSHOTBACK", "https://jw-app.org/services/uploadScreenshotDownload.php?versammlungid=4&gebietid=261&side=back&type=jpeg");
// $tpl->AssignLocal("main", "URLSCREENSHOTBACK", "./screenshotsGebiete/4/sc-261-back.png");
$tpl->parse();
ob_start(); //startet Buffer
$tpl->QuickPrint();
$content=ob_get_contents(); //Buffer wird in $var geschrieben
ob_end_clean(); //Buffer wird gelöscht
$pdf = "region.pdf";
//echo $content;
if (isset($_GET["html"]))
{
echo $content;
}
else
{
//define("DOMPDF_DPI", 140);
$html2pdf = new HTML2PDF( $orientation, $format, 'de', true, 'UTF-8', array(1, 1, 1, 1) );
$html2pdf->setDefaultFont( 'Arial' );
$html2pdf->AddFont('arialrounded', 'normal', 'arialrounded.php');
$html2pdf->setDefaultFont( 'arialrounded' );
//$html2pdf->SetDPI(144);
$html2pdf->WriteHTML( $content ); // <--- html
$html2pdf->Output( $pdf); // $pdf = filename
if ($filefront != null)
unlink ("./$dirTemp" . $filefront);
if ($fileback != null)
unlink ("./$dirTemp" . $fileback);
}
}
include("../exit.php");
?>