297 lines
13 KiB
PHP
297 lines
13 KiB
PHP
<?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("Filestore") ?>">Dateiablage</a></li>
|
|
<li class="breadcrumb-item active"><?= ($file->id) ? "bearbeiten" : "Neu" ?></li>
|
|
</ol>
|
|
</div>
|
|
<h4 class="page-title">Datei</h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- end page title -->
|
|
<?php
|
|
if (!$me->permissions->isAdmin) {
|
|
foreach ($networkaddresses as $networkaddress) {
|
|
if ($me->address->id == $networkaddress->address_id) {
|
|
$allowedNetworks[$networkaddress->network_id] = "ok";
|
|
}
|
|
}
|
|
}
|
|
|
|
if (empty($mode) && $filestorehistory) {
|
|
$mode = "edit-history";
|
|
}
|
|
?>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
|
|
<div class="card bg-light">
|
|
<div class="card-body">
|
|
<h4 class="header-title mb-2"><?= ($file->id) ? "Datei bearbeiten" : "Neue Datei" ?></h4>
|
|
<form class="form-horizontal" method="post" enctype="multipart/form-data"
|
|
action="<?= self::getUrl("Filestore", "save", ["mode" => $mode]) ?>">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
|
|
<input type="hidden" name="id" value="<?= $file->id ?>"/>
|
|
<input type="hidden" name="mode" value="<?= $mode ?>"/>
|
|
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="name">Name *</label>
|
|
<div class="col-lg-10">
|
|
<?php if (empty($mode) && !$filestorehistory) : ?>
|
|
<input value="<?= $file->name ?>" class="form-control"
|
|
name="name"
|
|
id="name">
|
|
<?php else : ?>
|
|
<span><?= $file->name ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="network_id">Netzgebiet *</label>
|
|
<div class="col-lg-10">
|
|
<?php if (empty($mode) && !$filestorehistory) : ?>
|
|
<select class="select2 form-control "
|
|
name="network_id" id="network_id">
|
|
<option value=""> </option>
|
|
<?php foreach ($networks as $key => $network):
|
|
if (!$me->permissions->isAdmin) {
|
|
if (!array_key_exists($network->id, $allowedNetworks)) {
|
|
continue;
|
|
}
|
|
}
|
|
?>
|
|
<option value="<?= $network->id ?>" <?= ($file->network_id == $network->id) ? "selected='selected'" : "" ?>><?= ($network->name) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<?php else :
|
|
foreach ($networks as $key => $network):
|
|
if (($file->network_id == $network->id)) :
|
|
$networkName = $network->name;
|
|
endif;
|
|
endforeach;
|
|
?>
|
|
<span class="col-form-label"><?= $networkName ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="description">Beschreibung</label>
|
|
<div class="col-lg-10">
|
|
<textarea class="form-control" name="description"
|
|
id="description"><?= htmlentities($file->description) ?></textarea>
|
|
</div>
|
|
</div>
|
|
<?php if (empty($mode) || $mode=="add-version") : ?>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2 col-form-label" for="filestore">Datei</label>
|
|
<div class="col-lg-10">
|
|
<input type="file" class="form-control-file" id="filestore"
|
|
name="filestore">
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="form-group row">
|
|
<label class="col-lg-2"></label>
|
|
<div class="col-lg-10">
|
|
<button type="submit" class="btn btn-primary">Speichern</button>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
$("#network_id").select2({placeholder: ""});
|
|
$("#pop_id").select2({placeholder: "", allowClear: true,});
|
|
$("#type_id").select2({placeholder: ""});
|
|
$("#networksection_id").select2({placeholder: "", allowClear: true,});
|
|
|
|
// disable mousewheel on input number field when in focus
|
|
$('form').on('focus', 'input[type=number]', function (e) {
|
|
$(this).on('wheel.disableScroll', function (e) {
|
|
e.preventDefault();
|
|
})
|
|
});
|
|
$('form').on('blur', 'input[type=number]', function (e) {
|
|
$(this).off('wheel.disableScroll');
|
|
});
|
|
|
|
function updatePops() {
|
|
var network_id = $("#network_id").val();
|
|
if (!network_id) {
|
|
return true;
|
|
}
|
|
// get new pops
|
|
$.get("<?=self::getUrl("Pop", "Api")?>",
|
|
{
|
|
"do": "getPops",
|
|
network_id: network_id
|
|
},
|
|
function (success) {
|
|
if (success.status == "OK") {
|
|
//console.log(success);
|
|
var pops = success.result.pops;
|
|
if (typeof pops !== 'object' || pops === null) {
|
|
return true;
|
|
}
|
|
var selected = $("#pop_id option:selected").val();
|
|
$("#pop_id option:gt(0)").remove();
|
|
for (var pop_id in pops) {
|
|
$("#pop_id").append($("<option></option>").attr("value", pop_id).text(pops[pop_id]));
|
|
}
|
|
if (selected) {
|
|
$("#pop_id").val(selected);
|
|
}
|
|
}
|
|
},
|
|
'json'
|
|
);
|
|
}
|
|
|
|
function updateSections() {
|
|
var network_id = $("#network_id").val();
|
|
if (!network_id) {
|
|
return true;
|
|
}
|
|
|
|
$.get("<?=self::getUrl("Networksection", "Api")?>",
|
|
{
|
|
"do": "getSections",
|
|
network_id: network_id
|
|
},
|
|
function (success) {
|
|
if (success.status == "OK") {
|
|
var sections = success.result.sections;
|
|
if (typeof sections !== 'object' || sections === null) {
|
|
return true;
|
|
}
|
|
var selected = $("#networksection_id option:selected").val();
|
|
$("#networksection_id option:gt(0)").remove();
|
|
for (var section_id in sections) {
|
|
$("#networksection_id").append($("<option></option>").attr("value", section_id).text(sections[section_id]));
|
|
}
|
|
console.log("selected: " + selected);
|
|
if (selected) {
|
|
$("#networksection_id").val(selected);
|
|
}
|
|
}
|
|
},
|
|
'json'
|
|
);
|
|
}
|
|
|
|
function updatePermissions() {
|
|
var network_id = $("#network_id").val();
|
|
if (!network_id) {
|
|
return true;
|
|
}
|
|
|
|
var types = ["lineworker", "pipeworker"];
|
|
|
|
$.get("<?=self::getUrl("Network", "Api")?>",
|
|
{
|
|
"do": "getPermissions",
|
|
network_id: network_id,
|
|
types: types.join('|')
|
|
},
|
|
function (success) {
|
|
if (success.status == "OK") {
|
|
var perms = success.result.permissions;
|
|
if (typeof perms !== 'object' || perms === null) {
|
|
return true;
|
|
}
|
|
types.forEach(function (type) {
|
|
var selected = $("#" + type + "_id option:selected").val();
|
|
$("#" + type + "_id").empty();
|
|
$("#" + type + "_id").append($("<option></option>"));
|
|
for (var perm_id in perms[type]) {
|
|
$("#" + type + "_id").append($("<option></option>").attr("value", perm_id).text(perms[type][perm_id]));
|
|
}
|
|
if (selected) {
|
|
$("#" + type + "_id").val(selected);
|
|
}
|
|
});
|
|
}
|
|
},
|
|
'json'
|
|
);
|
|
}
|
|
|
|
function enableGpsInputs() {
|
|
$("#gps_lat").removeAttr("readonly");
|
|
$("#gps_long").removeAttr("readonly");
|
|
$("#edit-gps").remove();
|
|
}
|
|
|
|
function showGpsAgain() {
|
|
$("#gps-again").show();
|
|
$("#gps-again input[type=checkbox").prop("checked", true);
|
|
}
|
|
|
|
|
|
<?php if($building->gps_lat && $building->gps_long): ?>
|
|
////////////
|
|
// Map
|
|
////////////
|
|
var gpslat = <?=($building->gps_lat) ? $building->gps_lat : 0?>;
|
|
var gpslong = <?=($building->gps_long) ? $building->gps_long : 0?>;
|
|
console.log(gpslat + "," + gpslong);
|
|
|
|
// Building Map
|
|
var buildingMap = L.map('building-map').setView([gpslat, gpslong], 18);
|
|
|
|
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
|
|
//L.tileLayer('<?=self::getResourcePath()?>assets/map/{id}/{z}/{x}/{y}.png', {
|
|
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
|
|
minZoom: 12,
|
|
maxZoom: 22,
|
|
//id: 'OSMPublicTransport',
|
|
//id: 'mapbox.streets',
|
|
id: 'mapbox/streets-v11',
|
|
//id: 'mapbox.pirates',
|
|
accessToken: '<?=TT_MAPBOX_TILE_API_TOKEN?>'
|
|
}).addTo(buildingMap);
|
|
|
|
var marker = L.marker([gpslat, gpslong]).addTo(buildingMap);
|
|
<?php endif; ?>
|
|
|
|
|
|
$("#street, #zip, #city").change(function () {
|
|
showGpsAgain();
|
|
});
|
|
|
|
$("#edit-gps").click(function () {
|
|
enableGpsInputs();
|
|
});
|
|
|
|
$("#network_id").change(function () {
|
|
updatePops();
|
|
updatePermissions();
|
|
updateSections();
|
|
});
|
|
|
|
$(document).ready(function () {
|
|
updatePops();
|
|
updatePermissions();
|
|
updateSections();
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>
|