Added image upload to ConstructionConsent Form
This commit is contained in:
@@ -328,7 +328,9 @@
|
||||
<div class="borderpoint">
|
||||
<h3>Übersichtsplan / Planskizze</h3>
|
||||
|
||||
<img src="<?=$ressourcePathPrefix?>/borderpoint-cc.png" style="width: 600px; border: 1px solid #000" />
|
||||
<?php if($consent->file): ?>
|
||||
<img src="<?=$consent->file->file->asDataUrl()?>" style="max-width: 600px; border: 1px solid #000" />
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="signature-line mt-4">
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<?= ($Action == "add") ? "Neue " : "" ?>Zustimmungserklärung <?= ($Action == "edit") ? "bearbeiten " : "" ?>
|
||||
</h4>
|
||||
|
||||
<form class="form-horizontal" method="post" action="<?= self::getUrl("ConstructionConsent", "save") ?>">
|
||||
<form class="form-horizontal" method="post" action="<?= self::getUrl("ConstructionConsent", "save") ?>" enctype="multipart/form-data">
|
||||
<input type="hidden" name="id" value="<?=isset($item) ? $item->id : ""?>"/>
|
||||
|
||||
<div class="card">
|
||||
@@ -151,6 +151,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="name">Planskizze / Bilddatei</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="file" class="form-control" name="consent_plan_image" id="consent_plan_image" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
|
||||
<div class="form-group row mt-3">
|
||||
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
|
||||
|
||||
@@ -102,6 +102,14 @@ $pagination_entity_name = "Adressen";
|
||||
</tr><tr>
|
||||
<th>GSTNR</th>
|
||||
<td><?=$item->gstnr?></td>
|
||||
</tr><tr>
|
||||
<th>Plan/Skizze</th>
|
||||
<td>
|
||||
<?php if($item->file): ?>
|
||||
<!--img src="<?=self::getUrl("File", "Download", ["id" => $item->file->file_id])?>" style="max-width: 480px;"/-->
|
||||
<img src="<?=$item->file->file->asDataUrl()?>" style="max-width: 480px;" />
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr><tr>
|
||||
<th></th>
|
||||
<td></td>
|
||||
@@ -113,6 +121,8 @@ $pagination_entity_name = "Adressen";
|
||||
<td class="text-monospace"><?=date("d.m.Y H:i:s", $item->edit)?> (<?=$item->editor->name?>)</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ class ConstructionConsent extends mfBaseModel {
|
||||
private $adb_hausnummer;
|
||||
private $adb_strasse;
|
||||
private $owners;
|
||||
private $file;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
@@ -87,6 +88,15 @@ class ConstructionConsent extends mfBaseModel {
|
||||
return $this->owners;
|
||||
}
|
||||
|
||||
if($name == "file") {
|
||||
if(!$this->id) return null;
|
||||
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id]);
|
||||
if($file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
|
||||
@@ -106,7 +106,6 @@ class ConstructionConsentController extends mfBaseController {
|
||||
}
|
||||
|
||||
$this->layout()->set("item", $item);
|
||||
|
||||
}
|
||||
|
||||
protected function addAction() : void {
|
||||
@@ -227,8 +226,35 @@ class ConstructionConsentController extends mfBaseController {
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
if(is_array($_FILES) && array_key_exists("consent_plan_image", $_FILES) && !$_FILES['consent_plan_image']['error']) {
|
||||
try {
|
||||
// returns File object or throws Exception on error
|
||||
$file = mfUpload::handleFormUpload("consent_plan_image", false, TT_CONSTRUCTIONCONSENT_FILE_UPLOAD_SUBFOLDER);
|
||||
} catch (Exception $ex) {
|
||||
$this->layout()->setFlash("Fehler beim Hochladen: " . $ex->getMessage(), "warning");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
$ccf = ConstructionConsentFile::create([
|
||||
'constructionconsent_id' => $id,
|
||||
'file_id' => $file->id,
|
||||
'filename' => "zustimmungserklärung-".$item->id."-plan.png",
|
||||
]);
|
||||
|
||||
// delete previous image
|
||||
$img = ConstructionConsentFile::getFirst(["constructionconsent_id" => $id]);
|
||||
if($img) {
|
||||
$img->file->delete();
|
||||
$img->delete();
|
||||
}
|
||||
|
||||
if(!$ccf->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Hochladen", "warning");
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Zustimmungserklärung erfolgreich gespeichert", "success");
|
||||
$this->redirect("ConstructionConsent");
|
||||
$this->redirect("ConstructionConsent", "View", ["id" => $id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,26 @@ class File extends mfBaseModel {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function asBase64String() {
|
||||
$path = $this->getFullPath();
|
||||
if(!file_exists($path) || (!is_file($path) && !is_link($path))) {
|
||||
return TT_IMAGE_PLACEHOLDER_B64;
|
||||
}
|
||||
return base64_encode(file_get_contents($path));
|
||||
}
|
||||
|
||||
public function asDataUrl() {
|
||||
$path = $this->getFullPath();
|
||||
if(!file_exists($path) || (!is_file($path) && !is_link($path))) {
|
||||
$mime = "image/webp";
|
||||
$base64 = TT_IMAGE_PLACEHOLDER_B64;
|
||||
} else {
|
||||
$base64 = $this->asBase64String();
|
||||
$mime = $this->getMimetype();
|
||||
}
|
||||
return "data:$mime;base64,$base64";
|
||||
}
|
||||
public function getFullPath() {
|
||||
/*if(!is_numeric($this->id) || $this->id < 1) {
|
||||
throw new Exception("File not found", 4040);
|
||||
|
||||
Reference in New Issue
Block a user