543 lines
24 KiB
PHP
543 lines
24 KiB
PHP
<?php
|
|
$pagination_baseurl = $this->getUrl($Mod,"Index");
|
|
$pagination_baseurl_params = ["filter" => $filter];
|
|
$pagination_entity_name = "Objekte & Anschlüsse";
|
|
?>
|
|
<?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 active">Objekte</li>
|
|
</ol>
|
|
</div>
|
|
<h4 class="page-title">Objekte</h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- end page title -->
|
|
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
|
|
<div class="card">
|
|
<div class="card-body mb-3">
|
|
<h4 class="header-title mb-3">Filter</h4>
|
|
|
|
<form method="get" action="<?=self::getUrl("Building")?>">
|
|
<div class="row">
|
|
<div class="col-1">
|
|
<label class="form-label" for="filter_network_id">Netzgebiet</label>
|
|
<select name="filter[network_id]" id="filter_network_id" class="form-control">
|
|
<option></option>
|
|
<?php foreach($mynetworks as $fnet): ?>
|
|
<option value="<?=$fnet->id?>" <?=($filter['network_id'] == $fnet->id) ? "selected='selected'" : ""?>><?=$fnet->name?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-1">
|
|
<label class="form-label" for="filter_networksection_id">Bauabschnitt</label>
|
|
<select name="filter[networksection_id]" id="filter_networksection_id" class="form-control">
|
|
<option></option>
|
|
<?php foreach($mynetworks as $fnet): ?>
|
|
<?php if(is_array($fnet->sections) && count($fnet->sections)): ?>
|
|
<optgroup label="<?=$fnet->name?>">
|
|
<?php foreach($fnet->sections as $section): ?>
|
|
<option value="<?=$section->id?>" <?=($filter['networksection_id'] == $section->id) ? "selected='selected'" : ""?>><?=$section->name?></option>
|
|
<?php endforeach; ?>
|
|
</optgroup>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-2">
|
|
<label class="form-label" for="filter_status_id">Objektstatus</label>
|
|
<select name="filter[status_id]" id="filter_status_id" class="form-control">
|
|
<option></option>
|
|
<?php foreach(BuildingstatusModel::getAll() as $status): ?>
|
|
<option
|
|
value="<?=$status->id?>"
|
|
<?php if(is_array($filter)): ?>
|
|
<?=($filter['status_id'] == $status->id) ? "selected='selected'" : ""?>
|
|
<?php else: ?>
|
|
<?=(($me->is("pipeworker") && !$me->isAdmin()) && $status->id == 3) ? "selected='selected'" : ""?>
|
|
<?php endif; ?>
|
|
>
|
|
<?=$status->code?> - <?=__($status->name."-b")?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="col-1">
|
|
<label class="form-label" for="filter_code">Objekt ID</label>
|
|
<input type="text" class="form-control" name="filter[code]" id="filter_code" value="<?=$filter['code']?>" />
|
|
</div>
|
|
|
|
<div class="col-2">
|
|
<label class="form-label" for="filter_street">Straße</label>
|
|
<input type="text" class="form-control" name="filter[street]" id="filter_street" value="<?=$filter['street']?>" />
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
<div class="row mt-2">
|
|
<div class="col">
|
|
<button type="submit" class="btn btn-primary">Filter anwenden</button>
|
|
<a class="btn btn-secondary" href="<?=self::getUrl("Building")?>">Filter zurücksetzen</a>
|
|
</div>
|
|
<!--<div class="col">
|
|
<button class="btn btn-info" type="button" onclick="refreshMap()"><i class="far fa-map"></i> Auf Karte anzeigen</button>
|
|
</div>-->
|
|
</div>
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="row col" id="map-link">
|
|
<a href="#" class="btn btn-success" onclick="refreshMap()"><i class="far fa-map"></i> Übersichtskarte einblenden</a>
|
|
</div>
|
|
<div class="row hidden" id="map-row">
|
|
<div id="building-map" style="height:70vh; width: 100%"></div>
|
|
<div class="row mt-1">
|
|
<div class="col">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="centerMap()"><i class="far fa-dot-circle fa-fw"></i> Zentrieren</button>
|
|
<button type="button" class="btn btn-sm btn-outline-success" onclick="toggleTileset()" title="Zwischen Karte und Satellitenbild umschalten"><i class="far fa-arrow-right-arrow-left fa-fw"></i> Karte/Satellit</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body mb-3">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="float-left">
|
|
<h4 class="header-title">Liste aller Objekte</h4>
|
|
</div>
|
|
<div class="float-right">
|
|
<a class="btn btn-primary mb-2" href="<?=self::getUrl("Building", "add")?>"><i class="fas fa-plus"></i> Neues Objekt anlegen</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
|
|
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
|
|
|
|
<table class="table table-striped table-hover">
|
|
<tr>
|
|
<th>Netzgebiet</th>
|
|
<th>POP</th>
|
|
<th>Typ</th>
|
|
<th>Objekt ID</th>
|
|
<th>OAN ID</th>
|
|
<th>Adresse</th>
|
|
<th>Einheiten</th>
|
|
<th>Status</th>
|
|
<th></th>
|
|
</tr>
|
|
<?php foreach($buildings as $building): ?>
|
|
<tr class="building-list-tr" id="building-<?=$building->id?>">
|
|
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->network->name?></td>
|
|
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->pop->name?></td>
|
|
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->type->name?></td>
|
|
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->code?></td>
|
|
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->oan_id?></td>
|
|
<td onclick="toggleBuilding(<?=$building->id?>)">
|
|
<?=$building->street?><br />
|
|
<?=$building->zip?> <?=$building->city?>
|
|
</td>
|
|
<td onclick="toggleBuilding(<?=$building->id?>)"><?=$building->units?></td>
|
|
<td onclick="toggleBuilding(<?=$building->id?>)" class="text-monospace"><?=__($building->status->name."-b")?></td>
|
|
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
|
<a href="<?=self::getUrl("Building", "edit", ["id" => $building->id])?>"><i class="far fa-edit" title="Objekt Bearbeiten"></i></a>
|
|
<a href="<?=self::getUrl("Building", "delete", ["id" => $building->id])?>" class="text-danger" onclick="if(!confirm('Objekt wirklich löschen?')) return false;" title="Objekt Löschen"><i class="fas fa-trash"></i></a>
|
|
</td>
|
|
</tr>
|
|
<tr id="building-detail-<?=$building->id?>" style="display:none; background-color:#fff">
|
|
<td colspan="8">
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h4 class="card-title">Anschlüsse im Objekt <strong><?=$building->code?></strong></h4>
|
|
<p>
|
|
<?=$building->street?><br />
|
|
<?=$building->zip?> <?=$building->city?>
|
|
</p>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
|
|
<?php if(is_array($building->terminations) && count($building->terminations)): ?>
|
|
<table class="table table-bordered">
|
|
<tr>
|
|
<th>Anschluss ID</th>
|
|
<th>Bezeichung</th>
|
|
<th>Kontakt</th>
|
|
<th>Telefon</th>
|
|
<th>Email</th>
|
|
<th>Status</th>
|
|
<th></th>
|
|
</tr>
|
|
<?php foreach($building->terminations as $term): ?>
|
|
|
|
<tr>
|
|
<td><?=$term->code?></td>
|
|
<td>
|
|
|
|
<span id="term-name-<?=$term->id?>-text"><?=$term->name?></span>
|
|
<div class="input-group" id="term-name-<?=$term->id?>-input" style="display:none">
|
|
<input type="text" class="form-control" id="term-name-<?=$term->id?>-input" value="<?=$term->name?>" />
|
|
<div class="input-group-append">
|
|
<button type="button" class="btn btn-primary" title="Speichern" onclick="saveTerminationControl(<?=$term->id?>, 'name')"><i class="fas fa-check"></i></button>
|
|
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleTerminationControl(<?=$term->id?>, 'name')"><i class="fas fa-times"></i></button>
|
|
</div>
|
|
</div>
|
|
<div class="float-right" id="term-name-<?=$term->id?>-edit">
|
|
<i class="far fa-edit text-pink" style="cursor:pointer" title="Bezeichnung Bearbeiten" onclick="toggleTerminationControl(<?=$term->id?>, 'name')"></i>
|
|
</div>
|
|
|
|
</td>
|
|
<td>
|
|
|
|
<span id="term-contact-<?=$term->id?>-text"><?=$term->contact?></span>
|
|
<div class="input-group" id="term-contact-<?=$term->id?>-input" style="display:none">
|
|
<input type="text" class="form-control" value="<?=$term->contact?>" />
|
|
<div class="input-group-append">
|
|
<button type="button" class="btn btn-primary" title="Speichern" onclick="saveTerminationControl(<?=$term->id?>, 'contact')"><i class="fas fa-check"></i></button>
|
|
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleTerminationControl(<?=$term->id?>, 'contact')"><i class="fas fa-times"></i></button>
|
|
</div>
|
|
</div>
|
|
<div class="float-right" id="term-contact-<?=$term->id?>-edit">
|
|
<i class="far fa-edit text-pink" style="cursor:pointer" title="Kontakt Bearbeiten" onclick="toggleTerminationControl(<?=$term->id?>, 'contact')"></i>
|
|
</div>
|
|
|
|
</td>
|
|
<td>
|
|
|
|
<span id="term-phone-<?=$term->id?>-text"><?=$term->phone?></span>
|
|
<div class="input-group" id="term-phone-<?=$term->id?>-input" style="display:none">
|
|
<input type="text" class="form-control" value="<?=$term->phone?>" />
|
|
<div class="input-group-append">
|
|
<button type="button" class="btn btn-primary" title="Speichern" onclick="saveTerminationControl(<?=$term->id?>, 'phone')"><i class="fas fa-check"></i></button>
|
|
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleTerminationControl(<?=$term->id?>, 'phone')"><i class="fas fa-times"></i></button>
|
|
</div>
|
|
</div>
|
|
<div class="float-right" id="term-phone-<?=$term->id?>-edit">
|
|
<i class="far fa-edit text-pink" style="cursor:pointer" title="Telefon Bearbeiten" onclick="toggleTerminationControl(<?=$term->id?>, 'phone')"></i>
|
|
</div>
|
|
|
|
</td>
|
|
<td>
|
|
|
|
<span id="term-email-<?=$term->id?>-text"><?=$term->email?></span>
|
|
<div class="input-group" id="term-email-<?=$term->id?>-input" style="display:none">
|
|
<input type="text" class="form-control" value="<?=$term->email?>" />
|
|
<div class="input-group-append">
|
|
<button type="button" class="btn btn-primary" title="Speichern" onclick="saveTerminationControl(<?=$term->id?>, 'email')"><i class="fas fa-check"></i></button>
|
|
<button type="button" class="btn btn-secondary" title="Abbrechen" onclick="toggleTerminationControl(<?=$term->id?>, 'email')"><i class="fas fa-times"></i></button>
|
|
</div>
|
|
</div>
|
|
<div class="float-right" id="term-email-<?=$term->id?>-edit">
|
|
<i class="far fa-edit text-pink" style="cursor:pointer" title="Email Bearbeiten" onclick="toggleTerminationControl(<?=$term->id?>, 'email')"></i>
|
|
</div>
|
|
|
|
</td>
|
|
<td class="text-monospace"><?=__($term->status->name."-t")?></td>
|
|
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
|
<a href="<?=self::getUrl("Termination", "delete", ["id" => $term->id])?>" class="text-danger" onclick="if(!confirm('Objekt wirklich löschen?')) return false;" title="Objekt Löschen"><i class="fas fa-trash"></i></a>
|
|
</td>
|
|
</tr>
|
|
|
|
<?php endforeach; ?>
|
|
</table>
|
|
|
|
<?php endif; ?>
|
|
<h4>Neuer Anschluss</h4>
|
|
<form method="post" action="<?=self::getUrl("Termination", "save")?>">
|
|
<input type="hidden" name="building_id" value="<?=$building->id?>" />
|
|
<table class="table tale-bordered">
|
|
<tr>
|
|
<td><input type="text" class="form-control" value="<automatisch generiert>" disabled="disabled" /></td>
|
|
<td><input type="text" class="form-control" name="name" value="" placeholder="Bezeichnung" /></td>
|
|
<td><input type="text" class="form-control" name="contact" value="" placeholder="Kontakt" /></td>
|
|
<td><input type="text" class="form-control" name="phone" value="" placeholder="Telefon" /></td>
|
|
<td><input type="text" class="form-control" name="email" value="" placeholder="Email" /></td>
|
|
<td><button type="submit" class="btn btn-primary">Speichern</button></td>
|
|
</tr>
|
|
</table>
|
|
</form>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr style="display:none;">
|
|
<td colspan="3"></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</table>
|
|
|
|
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
|
|
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
function toggleBuilding(id) {
|
|
$('#building-detail-' + id).toggle();
|
|
if($('#building-detail-' + id).is(":hidden")) {
|
|
$('#building-' + id).removeClass("table-info");
|
|
$('#building-' + id).removeClass("text-info");
|
|
} else {
|
|
$('#building-' + id).addClass("text-info");
|
|
$('#building-' + id).addClass("table-info");
|
|
}
|
|
}
|
|
|
|
function toggleTerminationControl(id, type) {
|
|
$("#term-" + type + "-" + id + "-text").toggle();
|
|
$("#term-" + type + "-" + id + "-input").toggle();
|
|
$("#term-" + type + "-" + id + "-edit").toggle();
|
|
}
|
|
|
|
function saveTerminationControl(id, type) {
|
|
if(!Number.isInteger(id) || id < 1) {
|
|
return false;
|
|
}
|
|
|
|
var value = $("#term-" + type + "-" + id + "-input input[type=text]").val();
|
|
|
|
$.post("<?=self::getUrl("Termination","Api")?>",
|
|
{
|
|
'do': "setValue",
|
|
id: id,
|
|
type: type,
|
|
value: value
|
|
},
|
|
function(success) {
|
|
if(success.status == "OK") {
|
|
$("#term-" + type + "-" + id + "-text").text(value);
|
|
} else {
|
|
console.log("error saving (" + type + ", '" + value + "')");
|
|
}
|
|
|
|
toggleTerminationControl(id, type);
|
|
},
|
|
'json');
|
|
}
|
|
|
|
/*
|
|
* Globals for map display
|
|
*/
|
|
|
|
var buildingMap;
|
|
var buildings = [];
|
|
var markers = [];
|
|
var markerState = true;
|
|
var mapCenterPos = [<?=TT_PLACEHOLDER_GPS_LAT?>, <?=TT_PLACEHOLDER_GPS_LONG?>];
|
|
var tileLayers = [];
|
|
var tilesets = ["mapbox/streets-v12", "mapbox/satellite-streets-v12"];
|
|
var currentTileset = "mapbox/streets-v12";
|
|
|
|
function toggleTileset() {
|
|
if(currentTileset == "mapbox/streets-v12") {
|
|
currentTileset = "mapbox/satellite-streets-v12";
|
|
} else {
|
|
currentTileset = "mapbox/streets-v12";
|
|
}
|
|
|
|
console.log("renderMap");
|
|
renderMap(true);
|
|
}
|
|
|
|
function refreshMap() {
|
|
// get buildings and render map
|
|
$('#map-link').hide();
|
|
$('#map-row').show();
|
|
getMapdata();
|
|
$([document.documentElement, document.body]).animate({
|
|
scrollTop: $("#building-map").offset().top - 150
|
|
}, 500);
|
|
}
|
|
|
|
function renderMap(tilesetChangeOnly = false) {
|
|
if(buildingMap) {
|
|
if(!tilesetChangeOnly) {
|
|
markers.forEach(function(m) {
|
|
buildingMap.removeLayer(m);
|
|
});
|
|
}
|
|
} else {
|
|
buildingMap = L.map('building-map').setView([<?=TT_PLACEHOLDER_GPS_LAT?>, <?=TT_PLACEHOLDER_GPS_LONG?>], 12);
|
|
}
|
|
|
|
if(!(currentTileset in tileLayers)) {
|
|
tileLayers[currentTileset] = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
|
|
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: 6,
|
|
maxZoom: 22,
|
|
id: currentTileset,
|
|
accessToken: '<?=TT_MAPBOX_TILE_API_TOKEN?>'
|
|
});
|
|
}
|
|
|
|
|
|
tileLayers[currentTileset].addTo(buildingMap);
|
|
// remove all tilesets not currently wanted
|
|
tilesets.forEach(function(t) {
|
|
if(t != currentTileset && buildingMap.hasLayer(tileLayers[t])) {
|
|
buildingMap.removeLayer(tileLayers[t]);
|
|
}
|
|
});
|
|
|
|
L.MakiMarkers.accessToken = '<?=TT_MAPBOX_TILE_API_TOKEN?>';
|
|
|
|
if(!tilesetChangeOnly) {
|
|
addMarkers();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function addMarkers() {
|
|
if(!Array.isArray(buildings) | !buildings.length) {
|
|
return false;
|
|
}
|
|
// draw markers and calculate center position
|
|
var all_coords = [];
|
|
buildings.forEach(function(building) {
|
|
if(!building.gps_lat || !building.gps_long) {
|
|
return;
|
|
}
|
|
var gps = [building.gps_lat, building.gps_long];
|
|
all_coords.push(gps);
|
|
|
|
var icon_color = "#ec98a2";
|
|
var icon_name = "home";
|
|
|
|
if(building.status == "connected") {
|
|
icon_color = "#acf0ab";
|
|
} else if(building.status == "pipework-done") {
|
|
icon_color = "#ffcd8b";
|
|
}
|
|
|
|
if(building.type.match(/^(Zwei)/i)) {
|
|
icon_name = "town";
|
|
} else if(building.type.match(/^(Mehr)/i)) {
|
|
icon_name = "city";
|
|
} else if(building.type.match(/^(Unternehmen)/i)) {
|
|
icon_name = "industry";
|
|
} else if(building.type.match(/^(Sender)/i)) {
|
|
icon_name = "communications-tower";
|
|
}
|
|
|
|
var marker_popup_content = '<?php include(realpath(dirname(__FILE__))."/include/building_popup.php");?>';
|
|
|
|
[["street", building.street], ["zip", building.zip], ["city", building.city], ["type", building.type], ["code", building.code], ["popname", building.popname], ["gps", building.gps_lat + ", " + building.gps_long],
|
|
["contact", building.contact], ["phone", building.phone], ["email", building.email]
|
|
].forEach(function(item) {
|
|
marker_popup_content = marker_popup_content.replaceAll("{{" + item[0].toUpperCase() + "}}", item[1]);
|
|
});
|
|
|
|
var icon = L.MakiMarkers.icon({icon: icon_name, color: icon_color, size: "l"});
|
|
var marker = L.marker(gps, {icon: icon}).addTo(buildingMap).bindPopup(marker_popup_content);
|
|
markers[building.id] = marker;
|
|
});
|
|
|
|
console.log(all_coords);
|
|
// calculate center position
|
|
mapCenterPos = GetCenterFromDegrees(all_coords);
|
|
console.log(mapCenterPos);
|
|
buildingMap.setView(mapCenterPos, 12);
|
|
|
|
return true;
|
|
}
|
|
|
|
function centerMap() {
|
|
buildingMap.setView(mapCenterPos, 12);
|
|
}
|
|
|
|
// gets buildings and calls renderMap()
|
|
function getMapdata() {
|
|
filter = getFilter();
|
|
|
|
$.post('<?=self::getUrl("Building", "Api")?>', {
|
|
'do': "getFilteredBuildings",
|
|
filter: filter
|
|
},function(success) {
|
|
if(success.status == "OK") {
|
|
console.log(success);
|
|
|
|
if(Array.isArray(success.result.buildings)) {
|
|
buildings = success.result.buildings;
|
|
renderMap();
|
|
}
|
|
}
|
|
},
|
|
'json'
|
|
);
|
|
|
|
}
|
|
|
|
function getFilter() {
|
|
var fields = ['network_id', 'networksection_id', 'status_id', 'code', 'street'];
|
|
var filter = {};
|
|
fields.forEach(function(field) {
|
|
if(!field) {
|
|
return;
|
|
}
|
|
let val = $('#filter_' + field).val();
|
|
if(val.length) {
|
|
filter[field] = val;
|
|
}
|
|
});
|
|
|
|
return filter;
|
|
}
|
|
|
|
// navigation
|
|
var building;
|
|
var hash = window.location.hash.substr(1);
|
|
var match = hash.match(/building=(\d+)/);
|
|
if(match && match[1]) {
|
|
building = match[1]
|
|
toggleBuilding(building);
|
|
|
|
//$('body').scrollTop($('#building-' + building).offset() - 50);
|
|
}
|
|
|
|
<?php if(is_array($filter) && count($filter)): ?>
|
|
//refreshMap();
|
|
<?php endif; ?>
|
|
</script>
|
|
|
|
|
|
|
|
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|