223 lines
9.9 KiB
PHP
223 lines
9.9 KiB
PHP
<?php
|
|
if(!isset($error_items)) $error_items = [];
|
|
?>
|
|
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
|
|
|
|
<!-- start page title -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box">
|
|
<div class="page-title-right">
|
|
<ol class="breadcrumb m-0">
|
|
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
|
|
<li class="breadcrumb-item"><a href="<?=self::getUrl("Contract")?>">Aktive Produkte</a></li>
|
|
<li class="breadcrumb-item"><a href="<?=self::getUrl("Contract", "view", ['id' => $contract->id])?>"><?=$contract->product_name?> [<?=$contract->matchcode?>]</a></li>
|
|
<li class="breadcrumb-item active">Konfiguration</li>
|
|
</ol>
|
|
</div>
|
|
<h4 class="page-title">Aktives Produkt</h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- end page title -->
|
|
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<a href="<?=self::getUrl("Contract","View", ['id' => $contract->id])?>" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Vertragsansicht</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card border-top-success">
|
|
<div class="card-body">
|
|
<h3 class="text-center mb-3"><?=$contract->product_name?> (<?=$contract->id?>)</h3>
|
|
|
|
<table class="table table-sm table-striped view-table">
|
|
<tr>
|
|
<th style="max-width: 50vw;">Matchcode:</th>
|
|
<td style="width: 50vw;"><?=$contract->matchcode?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Vertragsinhaber:</th>
|
|
<td><a href="<?=self::getUrl("Address", "View", ["id" => $contract->owner->id])?>"><?=$contract->owner->getCompanyOrName()?> (<?=$contract->owner->customer_number?>)</a></td>
|
|
</tr>
|
|
<tr>
|
|
<th>Produkt:</th>
|
|
<td><?=$contract->product_name?></td>
|
|
</tr><tr>
|
|
<th>Produkt Info:</th>
|
|
<td><?=$contract->product_info?></td>
|
|
</tr>
|
|
</table>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="card border-top-info">
|
|
<div class="card-body">
|
|
<h4 class="text-center mb-3">Konfiguration bearbeiten</h4>
|
|
<?php if(is_array($groups) && count($groups)): ?>
|
|
<form id="contract-config-form" method="post" action="<?=self::getUrl("Contractconfig", "Save")?>">
|
|
<input type="hidden" name="contract_id" value="<?=$contract->id?>" />
|
|
<table class="table table-sm table-borderless view-table">
|
|
<?php foreach($groups as $group): ?>
|
|
<tr class="bg-light">
|
|
<th><h4><u><?=$group->name?></u></h4></td>
|
|
<td></td>
|
|
</tr>
|
|
<?php foreach($group->items as $item): ?>
|
|
<?php
|
|
$inputname = "itemvalues[".$item->id."]";
|
|
if($item->multiple) {
|
|
$inputname .= "[]";
|
|
}
|
|
$inputid = "itemvalues_".$item->id;
|
|
$array_count = 0;
|
|
?>
|
|
<?php if($item->multiple): ?>
|
|
<?php foreach($item->getValue() as $item_value): ?>
|
|
<tr id="tr-<?=$inputid?>_<?=$array_count?>">
|
|
<th style="max-width: 50vw;"><?=$item->displayname?><span class="array_counter"> (<?=$array_count + 1?>)</span>:</th>
|
|
<td style="width: 50vw;">
|
|
<input type="text"
|
|
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
|
|
name="<?=$inputname?>"
|
|
id="<?=$inputid?>_<?=$array_count?>"
|
|
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id][$array_count]) : htmlentities($item_value)?>"
|
|
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
|
|
<small><?=$item->description?></small>
|
|
</td>
|
|
</tr>
|
|
<?php $array_count++; ?>
|
|
<?php endforeach; ?>
|
|
<tr id="tr-<?=$inputid?>_<?=$array_count?>">
|
|
<th style="max-width: 50vw;"><?=$item->displayname?><span class="array_counter"> (<?=$array_count + 1?>)</span>:</th>
|
|
<td style="width: 50vw;">
|
|
<input type="text"
|
|
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
|
|
name="<?=$inputname?>"
|
|
id="<?=$inputid?>_<?=$array_count?>"
|
|
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id][$array_count]) : ""?>"
|
|
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
|
|
<small><?=$item->description?></small>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<tr id="tr-<?=$inputid?>_0">
|
|
<th style="max-width: 50vw;"><?=$item->displayname?>:</th>
|
|
<td style="width: 50vw;">
|
|
<?php if($item->type == "enum"): ?>
|
|
<select class="form-control" name="<?=$inputname?>" id="<?=$inputid?>" <?=($item->multiple) ? "data-item-multiple='true'" : ""?>>
|
|
<?php foreach($item->getTypedataArray() as $option): ?>
|
|
<option value="<?=htmlentities($option)?>" <?=($item->getValue() == $option) ? "selected='selected'" : ""?>><?=htmlentities($option)?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<?php else: ?>
|
|
<input type="text"
|
|
class="form-control <?=(is_array($error_items) && in_array($item->id, $error_items)) ? "invalid" : ""?>"
|
|
name="<?=$inputname?>"
|
|
id="<?=$inputid?>_0"
|
|
value="<?=(isset($request)) ? htmlentities($request->itemvalues[$item->id]) : htmlentities($item->getValue())?>"
|
|
<?=($item->multiple) ? "data-item-multiple='true'" : ""?> />
|
|
<?php endif; ?>
|
|
<small><?=$item->description?></small>
|
|
</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
<?php endforeach; ?>
|
|
</table>
|
|
|
|
|
|
<div class="row">
|
|
<div class="col text-center">
|
|
<input type="submit" class="btn btn-primary" value="Konfiguration speichern" />
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<a href="<?=self::getUrl("Contract","View", ['id' => $contract->id])?>" class="btn btn-sm btn-secondary mr-1"><i class="fas fa-list"></i> Zurück zur Vertragsansicht</a>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$("#contract-config-form input").each(function() {
|
|
var input = this;
|
|
if(!$(input).attr("name")) return;
|
|
|
|
//console.log(this);
|
|
console.log($(input).attr("name"));
|
|
if($(input).data("item-multiple")) {
|
|
$(input).change(function() {
|
|
addMultipleValueField($(this).prop("id"));
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
function addMultipleValueField(id) {
|
|
console.log(id);
|
|
|
|
var id_match = id.match(/^itemvalues_(\d+)_(\d+)$/);
|
|
var elem_id = id_match[1];
|
|
var last_elem_count = 0;
|
|
|
|
var stop = false;
|
|
|
|
// find last input
|
|
$("input[id^=itemvalues_" + elem_id + "_").each(function() {
|
|
console.log("input id: " + this.id)
|
|
console.log("value: " + $(this).val());
|
|
|
|
if(!$(this).val()) {
|
|
stop = true;
|
|
return false;
|
|
}
|
|
var this_count_match = this.id.match(/^itemvalues_\d+_(\d+)$/);
|
|
var this_count = this_count_match[1]
|
|
if(this_count.length) {
|
|
console.log("last_elem_count: " + last_elem_count);
|
|
console.log("this count: " + this_count)
|
|
last_elem_count = Math.max(this_count, last_elem_count);
|
|
}
|
|
});
|
|
|
|
if(stop) {
|
|
return;
|
|
}
|
|
|
|
if(!elem_id.length && !last_elem_count.length) {
|
|
return;
|
|
}
|
|
|
|
var new_tr = $("#tr-" + id).clone();
|
|
console.log(new_tr);
|
|
|
|
var new_count = parseInt(last_elem_count) + 1;
|
|
new_tr.prop("id", "tr-itemvalues_" + elem_id + "_" + new_count);
|
|
|
|
new_tr.find("td input[type=text]").prop("id", "itemvalues_" + elem_id + "_" + new_count);
|
|
new_tr.find("td input[type=text]").val("");
|
|
new_tr.find("td input[type=text]").change(function() {
|
|
addMultipleValueField($(this).prop("id"));
|
|
});
|
|
new_tr.find("span.array_counter").text(" (" + (parseInt(new_count) + 1) + ")");
|
|
$(new_tr).insertAfter($("#tr-" + id));
|
|
|
|
}
|
|
</script>
|
|
|
|
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|