426 lines
16 KiB
PHP
426 lines
16 KiB
PHP
<?php
|
|
/******************************************************************************
|
|
* YMS - Yacht Management Software
|
|
* Copyright (C) 2024 Thomas Hooge
|
|
*
|
|
* SPDX-License-Identifier: WTFPL
|
|
******************************************************************************/
|
|
|
|
require 'globals.inc';
|
|
$pagetitle = _('Start');
|
|
|
|
// ========== ACTIONS START ===================================================
|
|
|
|
switch ($submit = form_get_action()) {
|
|
|
|
case NULL: break;
|
|
|
|
case 'add': $action = ACT_ADD; break;
|
|
case 'view': $action = ACT_DEFAULT; break;
|
|
case 'edit': $action = ACT_EDIT; break;
|
|
|
|
case 'select':
|
|
$vid = gpc_get_int($_POST, 'vid', 1);
|
|
$sql = "UPDATE settings SET valint=? WHERE userid=? AND sno=1";
|
|
$sth = $pdo->prepare($sql);
|
|
try {
|
|
$sth->execute([$vid, $user->id]);
|
|
} catch (PDOException $e) {
|
|
$g_error->Add('SQL-Error: '. $e->getMessage());
|
|
}
|
|
$g_message->Add(sprintf(_('Selected vessel %d'), $vid));
|
|
$user->load_vessel();
|
|
break;
|
|
|
|
case 'insert':
|
|
$action = ACT_DEFAULT;
|
|
if ($user->role != 'captain') {
|
|
$g_error->Add(_('Access denied. You are not the captain.'));
|
|
break;
|
|
}
|
|
$p[':vesselname'] = gpc_get_string($_POST, 'vesselname');
|
|
$p[':model'] = gpc_get_string($_POST, 'model');
|
|
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
|
$id = db_exec_insert('vessel', $p);
|
|
// autoselect newly created vessel
|
|
$sql = "UPDATE settings SET valint=? WHERE userid=? AND sno=1";
|
|
$sth = $pdo->prepare($sql);
|
|
try {
|
|
$sth->execute([$id, $user->id]);
|
|
} catch (PDOException $e) {
|
|
$g_error->Add('SQL-Error: '. $e->getMessage());
|
|
}
|
|
$g_message->Add(sprintf(_('Selected new vessel %d'), $id));
|
|
$user->load_vessel();
|
|
break;
|
|
|
|
case 'update':
|
|
if ($user->role != 'captain') {
|
|
$g_error->Add(_('Access denied. You are not the captain.'));
|
|
break;
|
|
}
|
|
$p[':vid'] = gpc_get_int($_POST, 'id');
|
|
// $p[':vtype'] = gpc_get_string($_POST, 'vtype');
|
|
$p[':vesselname'] = gpc_get_string($_POST, 'vesselname');
|
|
$p[':model'] = gpc_get_string($_POST, 'model');
|
|
$p[':loa'] = gpc_get_float($_POST, 'loa');
|
|
$p[':lwl'] = gpc_get_float($_POST, 'lwl');
|
|
$p[':beam'] = gpc_get_float($_POST, 'beam');
|
|
$p[':draught'] = gpc_get_float($_POST, 'draught');
|
|
$p[':draught_min'] = gpc_get_float($_POST, 'draught_min');
|
|
$p[':displacement'] = gpc_get_int($_POST, 'displacement');
|
|
$p[':ballast'] = gpc_get_int($_POST, 'ballast');
|
|
$p[':beltpos_aft'] = gpc_get_float($_POST, 'beltpos_aft');
|
|
$p[':beltpos_bow'] = gpc_get_float($_POST, 'beltpos_bow');
|
|
$p[':shapefile'] = gpc_get_string($_POST, 'shapefile');
|
|
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
|
db_exec_update('vessel', $p, 'vid');
|
|
$action = ACT_DEFAULT;
|
|
break;
|
|
|
|
default:
|
|
$g_error->Add(_('Unknown function!'));
|
|
$valid = FALSE;
|
|
|
|
}
|
|
|
|
// ========== ACTIONS END =====================================================
|
|
|
|
require 'header.php';
|
|
|
|
// ========== PAGE CONTENT ====================================================
|
|
|
|
if ($action == ACT_DEFAULT):
|
|
// ========== VARIANT: default behavior =======================================
|
|
|
|
|
|
echo '<h1>', _('Yacht data'), "</h1>\n";
|
|
|
|
echo '<p>', _('User'), ': ', $user->displayname, ' (', $user->role, ')', "</p>\n";
|
|
|
|
// Fetch current selected vessel number
|
|
$sql = "SELECT valint FROM settings WHERE userid=? AND sno=1";
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->execute([$user->id]);
|
|
$res = $sth->fetch(PDO::FETCH_NUM);
|
|
$vid = ($res[0]);
|
|
|
|
// Switch between vessels
|
|
$sth = $pdo->query("SELECT vid, vesselname, model FROM vessel ORDER BY vid");
|
|
$res = $sth->fetchAll();
|
|
echo '<form class="row" method="post">', "\n";
|
|
echo '<div class="col-1">', "\n";
|
|
echo '<label class="form-label" for="vid">Yacht:</label>';
|
|
echo "</div>\n";
|
|
echo '<div class="col-4">', "\n";
|
|
echo '<select class="form-select" name="vid" id="vid">', "\n";
|
|
foreach ($res as $row) {
|
|
echo '<option value="', $row['vid'], '"', ($row['vid'] == $vid ? ' selected>' : '>');
|
|
echo $row['vesselname'], ' - ', $row['model'];
|
|
echo "</option>\n";
|
|
}
|
|
echo "</select>\n";
|
|
echo "</div>\n";
|
|
echo '<div class="col">', "\n";
|
|
echo '<button type="submit" class="btn btn-secondary" name="submit[select]">', _('Select'), '</button>', "\n";
|
|
echo '<button type="submit" class="btn btn-secondary" name="submit[add]">', _('Add yacht'), '</button>', "\n";
|
|
echo "</div>\n";
|
|
echo "</form>\n";
|
|
|
|
// Get current vessel data
|
|
$sql = "SELECT vesselname, model, loa, lwl, beam, draught, draught_min,"
|
|
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
|
|
. " remarks "
|
|
. "FROM vessel "
|
|
. "WHERE vid=?";
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->execute([$vid]);
|
|
$vessel = $sth->fetch();
|
|
|
|
// get vessel shape
|
|
// test for predefined base shape
|
|
$shapefilepath = dirname(__FILE__).'/'.$g_shapedir.'/'.$vessel['shapefile'];
|
|
if (isset($vessel['shapefile']) and file_exists($shapefilepath)) {
|
|
$baseshape = file_get_contents($shapefilepath);
|
|
} else {
|
|
// use internal default shape
|
|
$baseshape = <<<EOT
|
|
<svg version="1.1" width="1024" height="350" viewBox="0 0 1024 350" id="svg1">
|
|
<g id="g1">
|
|
<path id="path1" style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-dasharray:8, 4, 2, 4;stroke-dashoffset:0;stroke-opacity:1" d="M 3.3e-6,174.91172 1023.9982,174.90837" />
|
|
<path id="path2" style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1" d="m 1.1002728,174.9708 c 0,0 0.150828,-90.157538 0.02448,-103.853791 C 66.951611,46.573152 247.6267,3.4573666 430.56326,3.8276086 670.30694,4.3128215 758.66035,44.913257 838.18466,74.965511 917.70898,105.01776 1022.8821,175.00227 1022.8821,175.00227" />
|
|
<use id="use1" x="0" y="0" xlink:href="#path2" transform="matrix(1,0,0,-1,0.0781866,350.05682)" />
|
|
</g>
|
|
</svg>
|
|
EOT;
|
|
}
|
|
|
|
$shape = new SimpleXMLElement($baseshape);
|
|
$g = $shape->addChild('g');
|
|
$g->addAttribute('id', 'boxlayout');
|
|
|
|
// line for belt
|
|
$line = $g->addChild('line');
|
|
$line->addAttribute('x1', '100');
|
|
$line->addAttribute('y1', '0');
|
|
$line->addAttribute('x2', '100');
|
|
$line->addAttribute('y2', '350');
|
|
$line->addAttribute('style', 'stroke:#ff0000;stroke-width:1px');
|
|
|
|
// rectangle for storage
|
|
$rect = $g->addChild('rect');
|
|
$rect->addAttribute('x', '10');
|
|
$rect->addAttribute('y', '80');
|
|
$rect->addAttribute('width', '40');
|
|
$rect->addAttribute('height', '60');
|
|
$rect->addAttribute('stroke', '#000');
|
|
$rect->addAttribute('stroke-width', '1px');
|
|
$rect->addAttribute('fill', '#57E389');
|
|
$rect->addAttribute('fill-opacity', '0.4');
|
|
|
|
// text with link
|
|
$link = $g->addChild('a');
|
|
$link->addAttribute('xlink:href', 'storage.php?f=view&id=1');
|
|
$text = $link->addChild('text', 'Box1');
|
|
$text->addAttribute('font-size', '10');
|
|
$text->addAttribute('x', '14');
|
|
$text->addAttribute('y', '95');
|
|
|
|
?>
|
|
<div class="container-fluid my-4">
|
|
<?=$shape->asXML()?>
|
|
</div>
|
|
|
|
<div class="container-fluid">
|
|
<div class="row my-4">
|
|
<div class="col">
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?=_('Boat data') ?></h5>
|
|
<table class="table table-sm">
|
|
<tr><td><?=_('Loa')?></td><td><?=format_float($vessel['loa'], 2, 'm')?></td></tr>
|
|
<tr><td><?=_('Lwl')?></td><td><?=format_float($vessel['lwl'], 2, 'm')?></td></tr>
|
|
<tr><td><?=_('Beam')?></td><td><?=format_float($vessel['beam'], 2, 'm')?></td></tr>
|
|
<tr><td><?=_('Draught')?></td><td><?=format_float($vessel['draught'], 2, 'm')?></td></tr>
|
|
<tr><td><?=_('Draught, min.')?></td><td><?=format_float($vessel['draught_min'], 2, 'm')?></td></tr>
|
|
<tr><td><?=_('Displacement')?></td><td><?=$vessel['displacement']?> kg</td></tr>
|
|
<tr><td><?=_('Ballast')?></td><td><?=$vessel['ballast']?> kg</td></tr>
|
|
<tr><td><?=_('Belt position aft')?></td><td><?=format_float($vessel['beltpos_aft'], 2, 'm')?></td></tr>
|
|
<tr><td><?=_('Belt position bow')?></td><td><?=format_float($vessel['beltpos_bow'], 2, 'm')?></td></tr>
|
|
</table>
|
|
<?php
|
|
// Edit vessel only for captain
|
|
if ($user->role == 'captain') {
|
|
echo '<a href="', $g_scriptname, '?f=edit&id=', $user->vid, '" class="btn btn-primary" role="button">', _('Edit'), "</a>\n";
|
|
}
|
|
?>
|
|
</div>
|
|
</div><?php /* card */ ?>
|
|
|
|
</div>
|
|
<div class="col">
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?=_('Statistics') ?></h5>
|
|
<?php
|
|
// Statistics
|
|
|
|
// Storage: 0 - default, 1 - tank
|
|
// $stype = [ 0 => _('Default'), 1 => _('Tank')];
|
|
$stype = db_get_options(3);
|
|
$sql = "SELECT stype, COUNT(stype) "
|
|
. "FROM storage "
|
|
. "WHERE vid=? "
|
|
. "GROUP BY stype "
|
|
. "ORDER BY stype";
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->execute([$vid]);
|
|
$res = $sth->fetchAll(PDO::FETCH_NUM);
|
|
echo '<table class="table table-sm">', "\n";
|
|
echo '<tr><td colspan="2">', _('Storage type') , "</td>";
|
|
foreach ($res as $row) {
|
|
echo "<tr><td>", $stype[$row[0]], "</td><td>", $row[1], "</td></tr>\n";
|
|
}
|
|
|
|
// Boxes
|
|
$sth = $pdo->prepare("SELECT COUNT(*) FROM box INNER JOIN storage USING (sid) WHERE vid=?");
|
|
$sth->execute([$user->vid]);
|
|
echo '<tr><td>', _('Boxes'), '</td><td>', $sth->fetchColumn(), "</td></tr>\n";
|
|
|
|
// Equipment
|
|
$sth = $pdo->prepare("SELECT COUNT(*) FROM equipment WHERE vid=?");
|
|
$sth->execute([$user->vid]);
|
|
echo '<tr><td colspan="2">', _('Equipment') , "</td>";
|
|
echo '<tr><td>', _('Count'), '</td><td>', $sth->fetchColumn(), "</td></tr>\n";
|
|
|
|
// Inventory
|
|
// All items from vessel storage and all items from boxes in vessel storage
|
|
$sql = "SELECT SUM(n) FROM ("
|
|
. "SELECT COUNT(*) AS n FROM inventory JOIN storage USING (sid) WHERE boxtype='storage' AND vid=:vid "
|
|
. "UNION "
|
|
. "SELECT COUNT(*) AS n FROM inventory JOIN box USING (boxid) JOIN storage ON (box.sid=storage.sid) WHERE boxtype='box' AND vid=:vid"
|
|
. ") AS x";
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->bindValue(':vid', $user->vid, PDO::PARAM_INT);
|
|
$sth->execute();
|
|
|
|
// Tasks
|
|
echo '<tr><td colspan="2">', _('Inventory') , "</td>";
|
|
echo '<tr><td>', _('Count'), '</td><td>', $sth->fetchColumn(), "</td></tr>\n";
|
|
|
|
|
|
echo "</table>\n";
|
|
|
|
?>
|
|
</div>
|
|
</div><?php /* card */ ?>
|
|
|
|
|
|
</div>
|
|
<div class="col">
|
|
|
|
<div class="card">
|
|
<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="storage.php"><?=_('Storage')?></a></li>
|
|
<li class="list-group-item"><a href="company.php"><?=_('Companies')?></a></li>
|
|
</ul>
|
|
<hr>
|
|
<h5 class="card-title"><?=_('Additional modules')?></h5>
|
|
<ul class="list-group list-group-flush">
|
|
<li class="list-group-item"><a href="measurement.php"><?=_('Measurements')?></a></li>
|
|
<li class="list-group-item"><a href="checklist.php"><?=_('Checklists')?></a></li>
|
|
<li class="list-group-item"><a href="search.php"><?=_('Search')?></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
</div><?php /* col */ ?>
|
|
</div><?php /* row */ ?>
|
|
</div>
|
|
|
|
<?php
|
|
|
|
elseif ($action == ACT_ADD):
|
|
// ========== VARIANT: add record =============================================
|
|
|
|
echo '<h2>', _('Add additional yacht'), "</h2>\n";
|
|
|
|
?>
|
|
<form method="post" action="<?=$g_scriptname?>">
|
|
<div class="mb-3">
|
|
<label for="vesselname" class="form-label"><?=_('Name')?></label>
|
|
<input type="text" class="form-control" id="vesselname" name="vesselname" required autofocus>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="model" class="form-label"><?=_('Model')?></label>
|
|
<input type="text" class="form-control" id="model" name="model">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
|
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$project->remarks ?></textarea>
|
|
</div>
|
|
<div class="container-fluid px-0 my-3">
|
|
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
|
|
<a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a>
|
|
</div>
|
|
</form>
|
|
|
|
<?php
|
|
|
|
elseif ($action == ACT_EDIT):
|
|
// ========== VARIANT: edit single record =====================================
|
|
|
|
// get list of shapefiles
|
|
$opt_shapefiles = array('' => _('--- none ---'));
|
|
foreach (glob($g_shapedir.'/*.svg') as $f) {
|
|
$f = basename($f);
|
|
$opt_shapefiles[$f] = $f;
|
|
}
|
|
|
|
$sql = "SELECT vesselname, vtype, model, loa, lwl, beam, draught, draught_min,"
|
|
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
|
|
. " remarks "
|
|
. "FROM vessel "
|
|
. "WHERE vid=?";
|
|
$sth = $pdo->prepare($sql);
|
|
$sth->execute([$user->vid]);
|
|
$vessel = $sth->fetch(PDO::FETCH_OBJ);
|
|
?>
|
|
<h2><?=_('Edit Yacht')?></h2>
|
|
<form method="post" action="<?=$g_scriptname?>">
|
|
<input type="hidden" name="id" value="<?=$user->vid?>">
|
|
<div class="mb-3">
|
|
<label for="vesselname" class="form-label"><?=_('Vesselname')?></label>
|
|
<input type="text" class="form-control" id="vesselname" name="vesselname" value="<?=$vessel->vesselname ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="model" class="form-label"><?=_('Model')?></label>
|
|
<input type="text" class="form-control" id="model" name="model" value="<?=$vessel->model ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="loa" class="form-label"><?=_('LoA')?></label>
|
|
<input type="text" class="form-control" id="loa" name="loa" value="<?=format_float($vessel->loa, 2) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="lwl" class="form-label"><?=_('LwL')?></label>
|
|
<input type="text" class="form-control" id="lwl" name="lwl" value="<?=format_float($vessel->lwl, 2) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="beam" class="form-label"><?=_('Beam')?></label>
|
|
<input type="text" class="form-control" id="beam" name="beam" value="<?=format_float($vessel->beam, 2) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="draught" class="form-label"><?=_('Draught')?></label>
|
|
<input type="text" class="form-control" id="draught" name="draught" value="<?=format_float($vessel->draught, 2) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="draught_min" class="form-label"><?=_('Draught, min.')?></label>
|
|
<input type="text" class="form-control" id="draught_min" name="draught_min" value="<?=format_float($vessel->draught_min, 2) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="displacement" class="form-label"><?=_('Displacement')?></label>
|
|
<input type="number" input-mode="decimal" min="0" max="100000" step="1" class="form-control" id="displacement" name="displacement" value="<?=$vessel->displacement ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="ballast" class="form-label"><?=_('Ballast')?></label>
|
|
<input type="number" input-mode="decimal" min="0" max="100000" step="1" class="form-control" id="ballast" name="ballast" value="<?=$vessel->ballast ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="beltpos_aft" class="form-label"><?=_('Belt position aft')?></label>
|
|
<input type="text" class="form-control" id="beltpos_aft" name="beltpos_aft" value="<?=format_float($vessel->beltpos_aft, 2) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="beltpos_bow" class="form-label"><?=_('Belt position bow')?></label>
|
|
<input type="text" class="form-control" id="beltpos_bow" name="beltpos_bow" value="<?=format_float($vessel->beltpos_bow, 2) ?>">
|
|
</div>
|
|
<?php /*
|
|
<div class="mb-3">
|
|
<label for="shapefile" class="form-label"><?=_('Shapefile')?></label>
|
|
<input type="text" class="form-control" id="shapefile" name="shapefile" value="<?=$vessel->shapefile ?>">
|
|
</div> */
|
|
form_create_select('shapefile', _('Shape file'), $opt_shapefiles, $vessel->shapefile);
|
|
?>
|
|
<div class="mb-3">
|
|
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
|
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$vessel->remarks ?></textarea>
|
|
</div>
|
|
<?php
|
|
|
|
form_edit_buttons($g_scriptname, $user->vid);
|
|
echo "</form>\n";
|
|
|
|
else:
|
|
// ========== ERROR UNKNOWN VARIANT ===========================================
|
|
|
|
echo '<p>', _('Unknown function call: Please report to system development!'), "</p>\n";
|
|
|
|
endif; // $action == ...
|
|
// ========== END OF VARIANTS =================================================
|
|
|
|
include 'footer.php';
|