Added default storage to vessel and some other fixes

This commit is contained in:
2026-07-20 13:05:15 +02:00
parent a01329fdab
commit 562aa587ad
10 changed files with 205 additions and 25 deletions
+34 -7
View File
@@ -79,6 +79,7 @@ switch ($submit = form_get_action()) {
$p[':shapefile'] = NULL;
}
$p[':shipyard'] = gpc_get_int($_POST, 'shipyard');
$p[':sid_default'] = gpc_get_uint($_POST, 'sid');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('vessel', $p, 'vid');
$action = ACT_DEFAULT;
@@ -448,13 +449,37 @@ echo '<h2>', _('Add additional yacht'), "</h2>\n";
elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
// get list of shapefiles
//$opt_shapefiles = array('' => _('--- none ---'));
$opt_shapefiles = $g_opt_none;
foreach (glob($g_shapedir.'/*.svg') as $f) {
$f = basename($f);
$opt_shapefiles[$f] = $f;
// 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);
} 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;
$opt_storage = db_get_opt_storage($user->vid);
$opt_shipyard = $g_opt_none + [-3 => _('&horbar; Custom-built &horbar;')];
$sql = "SELECT compid, compname FROM company WHERE comptype=3 ORDER BY compname";
@@ -465,7 +490,7 @@ foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
$sql = "SELECT vesselname, vtype, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
. " shipyard, remarks "
. " shipyard, sid_default, remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
@@ -526,6 +551,8 @@ $vessel = $sth->fetch(PDO::FETCH_OBJ);
</div> */
form_create_select('shapefile', _('Shape file'), $opt_shapefiles, $vessel->shapefile);
form_create_select('shipyard', _('Shipyard'), $opt_shipyard, $vessel->shipyard);
form_create_select('sid', _('Default Storage'), $g_opt_none + $opt_storage, $vessel->sid_default);
?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>