Webgui: user definable menu implemented

This commit is contained in:
2026-07-21 11:01:50 +02:00
parent 562aa587ad
commit a3d4825cbd
10 changed files with 490 additions and 300 deletions
+29 -32
View File
@@ -8,6 +8,7 @@
require 'globals.inc';
require 'lib/gpc.inc';
require 'lib/svg.inc';
$pagetitle = _('Start');
@@ -395,20 +396,26 @@ echo "</table>\n";
<div class="card-body">
<h5 class="card-title"><?=_('Base data')?></h5>
<ul class="list-group list-group-flush">
<li class="list-group-item"><a href="dropdown.php"><?=_('Selection lists')?></a></li>
<li class="list-group-item"><a href="tag.php"><?=_('Tags')?></a></li>
<li class="list-group-item"><a href="storage.php"><?=_('Storage')?></a></li>
<li class="list-group-item"><a href="company.php"><?=_('Companies')?></a></li>
<?php
// load all base modules not in main menu
foreach ($g_modules as $mid => $module) {
if (!in_array($mid, $user->menu) && ($module['group'] === 'base')) {
echo ' <li class="list-group-item"><a href="', $module['file'], '">', $module['title'],"</a></li>\n";
}
}
?>
</ul>
<hr>
<h5 class="card-title"><?=_('Additional modules')?></h5>
<ul class="list-group list-group-flush">
<li class="list-group-item"><a href="settings.php"><?=_('Settings')?></a></li>
<li class="list-group-item"><a href="task.php"><?=_('Tasks')?></a></li>
<li class="list-group-item"><a href="measurement.php"><?=_('Measurements')?></a></li>
<li class="list-group-item"><a href="cable.php"><?=_('Cables')?></a></li>
<li class="list-group-item"><a href="fuse.php"><?=_('Fuses')?></a></li>
<li class="list-group-item"><a href="checklist.php"><?=_('Checklists')?></a></li>
<?php
// load all main or extra modules not in main menu
foreach ($g_modules as $mid => $module) {
if (!in_array($mid, $user->menu) && ($module['group'] === 'extra' || $module['group'] === 'main')) {
echo ' <li class="list-group-item"><a href="', $module['file'], '">', $module['title'],"</a></li>\n";
}
}
?>
</ul>
</div>
</div>
@@ -451,30 +458,20 @@ elseif ($action == ACT_EDIT):
// check if there is a shapefile-index
$shapeindexfile = $g_doc_basepath . '/shapeindex.json';
$shapeindex = [];
if (!file_exists($shapeindexfile)) {
// try to read metadata from top of svg file
foreach (glob($g_shapedir.'/*.svg') as $f) {
$fh = fopen($f, 'r');
$fname = basename($f);
$header = fread($fh, 1024);
if (preg_match('/<title[^>]*>(.*?)<\/title>/is', $header, $match)) {
$title = trim($match[1]);
} else {
$title = $fname;
}
$shapeindex[$fname] = $title;
fclose($fh);
}
$json = json_encode($shapeindex, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
file_put_contents($shapeindexfile, $json);
$shapeindex = create_shapeindex($shapeindexfile);
} else {
// read svg metadata from existing file
$json = file_get_contents($shapeindexfile);
$shapeindex = json_decode($json, true);
if (json_last_error() !== JSON_ERROR_NONE) {
// TODO some kind of error and fallback
// perhaps regenerate index file?
// check if shapeindex needs refresh (older than one day)
if (time() - filemtime($shapeindexfile) > 86400) {
$shapeindex = create_shapeindex($shapeindexfile);
} else {
// read svg metadata from existing file
$json = file_get_contents($shapeindexfile);
$shapeindex = json_decode($json, true);
if (json_last_error() !== JSON_ERROR_NONE) {
// TODO some kind of error and fallback
// perhaps regenerate index file?
}
}
}
$opt_shapefiles = $g_opt_none + $shapeindex;