prepare($sql);
try {
$sth->execute([$vid, $user->id]);
} catch (PDOException $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
}
$user->load_vessel();
$g_message->Add(sprintf(_('Selected vessel %d: %s'), $vid, $user->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');
if ($p[':shapefile'] == '-1') {
$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;
break;
default:
$g_error->Add(_('Unknown function!'));
$valid = FALSE;
}
// ========== ACTIONS END =====================================================
require 'header.php';
// ========== PAGE CONTENT ====================================================
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
page_caption_search(_('Yacht data'));
echo '
', _('User'), ': ', $user->displayname, ' (', $user->role, ')', "
\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]);
// Get current vessel data
$sql = "SELECT vesselname, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
. " shipyard, remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$vid]);
$vessel = $sth->fetch(PDO::FETCH_OBJ);
echo '', "\n"; // head block
// Switch between vessels
?>
', "\n";
echo '
', "\n";
echo '
';
if ($vessel->shipyard && $vessel->shipyard > 0) {
if ($vessel->shipyard == -3) {
echo _('Custom-build');
} else {
$sql = "SELECT compname FROM company WHERE compid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$vessel->shipyard]);
echo sprintf(_('Built by %s'), $sth->fetchColumn());
// TODO year of build?
}
}
if (strlen($vessel->remarks) > 0) {
echo nl2br($vessel->remarks);
}
echo "
\n";
echo "
\n"; // row 2
echo "\n"; // end of yacht head block
// 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;
}
$shape = new SimpleXMLElement($baseshape);
// $shape['width'], $shape['height']
// offset for coordinate origin
$ox = 0;
$oy = 0;
$g = $shape->addChild('g');
$g->addAttribute('id', 'boxlayout');
// line for belt
if (isset($vessel->beltpos_aft) and isset($vessel->loa) and ($vessel->beltpos_aft < $vessel->loa)) {
$x = $ox + round($vessel->beltpos_aft / $vessel->loa * 1024);
$line = $g->addChild('line');
$line->addAttribute('x1', $x);
$line->addAttribute('y1', $oy);
$line->addAttribute('x2', $x);
$line->addAttribute('y2', $shape['height']);
$line->addAttribute('style', 'stroke:#ff0000;stroke-width:1px');
}
if (isset($vessel->beltpos_bow) and isset($vessel->loa) and ($vessel->beltpos_bow < $vessel->loa)) {
$x = $ox + round($vessel->beltpos_bow / $vessel->loa * 1024);
$line = $g->addChild('line');
$line->addAttribute('x1', $x);
$line->addAttribute('y1', $oy);
$line->addAttribute('x2', $x);
$line->addAttribute('y2', $shape['height']);
$line->addAttribute('style', 'stroke:#ff0000;stroke-width:1px');
}
// select all visible storages
// - x,y,z is center of storage
// - todo: shape offset x and y for non centered shapes?
// read center line y-coordinate from shape?
if (isset($vessel->loa)) {
$f = $shape['width'] / ($vessel->loa * 1000);
$sql = "SELECT sid, sname, x, y, wx, wy FROM storage WHERE x>0 AND wx>0 AND wy>0 AND vid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$user->vid]);
foreach ($sth->fetchAll() as $row) {
$w = round($row['wx'] * $f);
$h = round($row['wy'] * $f);
$x = round($row['x'] * $f - $w / 2.0);
$y = round($row['y'] * $f + $shape['height'] / 2.0 - $h / 2.0);
$rect = $g->addChild('rect');
$rect->addChild('title', $row['sname']);
$rect->addAttribute('x', $x);
$rect->addAttribute('y', $y);
$rect->addAttribute('width', $w);
$rect->addAttribute('height', $h);
$rect->addAttribute('stroke', '#000');
$rect->addAttribute('stroke-width', '1px');
$rect->addAttribute('fill', '#57E389');
$rect->addAttribute('fill-opacity', '0.4');
}
// grid
// not yet production ready
/* $step = round($shape['width'] / ($vessel->loa * 10)); // 10cm steps
$x = $step;
$n = 0;
while ($x < ($vessel->loa * 1000)) {
$n += 1;
$line = $g->addChild('line');
$line->addAttribute('x1', $x);
$line->addAttribute('y1', '0');
$line->addAttribute('x2', $x);
$line->addAttribute('y2', $shape['height']);
if ($n % 10 == 0) {
$line->addAttribute('style', 'stroke:#0000dd;stroke-width:1px');
} else {
$line->addAttribute('style', 'stroke:#0000aa;stroke-width:0.3px');
}
$x += $step;
} */
}
// 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'); */
?>
asXML();
// strip first line: xml version ...
echo substr($xml, strpos($xml, "\n") + 1);
?>
=_('Boat data') ?>
| =_('Loa')?> | =format_float($vessel->loa, 2, 'm')?> |
| =_('Lwl')?> | =format_float($vessel->lwl, 2, 'm')?> |
| =_('Beam')?> | =format_float($vessel->beam, 2, 'm')?> |
| =_('Draught')?> | =format_float($vessel->draught, 2, 'm')?> |
| =_('Draught, min.')?> | =format_float($vessel->draught_min, 2, 'm')?> |
| =_('Displacement')?> | =$vessel->displacement?> kg |
| =_('Ballast')?> | =$vessel->ballast?> kg |
| =_('Belt position aft')?> | =format_float($vessel->beltpos_aft, 2, 'm')?> |
| =_('Belt position bow')?> | =format_float($vessel->beltpos_bow, 2, 'm')?> |
role == 'captain') {
echo '
', _('Edit'), "\n";
}
?>
=_('Statistics') ?>
_('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 '
', "\n";
echo '| ', _('Storage type') , " | ";
foreach ($res as $row) {
echo "
| | ", $stype[$row[0]], " | ", $row[1], " |
\n";
}
// Boxes
$sth = $pdo->prepare("SELECT COUNT(*) FROM box INNER JOIN storage USING (sid) WHERE vid=?");
$sth->execute([$user->vid]);
echo '| | ', _('Boxes'), ' | ', $sth->fetchColumn(), " |
\n";
// Equipment
$sth = $pdo->prepare("SELECT COUNT(*), SUM(weight) FROM equipment WHERE vid=?");
$sth->execute([$user->vid]);
$row = $sth->fetch(PDO::FETCH_NUM);
echo '| ', _('Equipment') , " | ";
echo '
| | ', _('Count'), ' | ', $row[0], " |
\n";
echo '| | ', _('Weight'), ' | ', format_float($row[1], 1, 'kg'), " |
\n";
// Inventory
// All items from vessel storage and all items from boxes in vessel storage
$sql = "SELECT SUM(n), SUM(w) FROM ("
. "SELECT COUNT(*) AS n, SUM(i.weight * i.number) as w FROM inventory AS i JOIN storage USING (sid) WHERE conttype='storage' AND vid=:vid "
. "UNION "
. "SELECT COUNT(*) AS n, SUM(i.weight * i.number) as w FROM inventory AS i JOIN box USING (boxid) JOIN storage ON (box.sid=storage.sid) WHERE conttype='box' AND vid=:vid"
. ") AS x";
$sth = $pdo->prepare($sql);
$sth->bindValue(':vid', $user->vid, PDO::PARAM_INT);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_NUM);
echo '| ', _('Inventory') , " | ";
echo '
| | ', _('Count'), ' | ', $row[0], " |
\n";
echo '| | ', _('Weight'), ' | ', format_float($row[1], 1, 'kg'), " |
\n";
// Documents
$sth = $pdo->query("SELECT COUNT(*) FROM document");
echo '| ', _('Documents') , " | ";
echo '
| | ', _('Count'), ' | ', $sth->fetchColumn(), " |
\n";
echo "
\n";
?>
=_('Base data')?>
=_('Additional modules')?>
', _('Add additional yacht'), "\n";
?>
]*>(.*?)<\/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 => _('― Custom-built ―')];
$sql = "SELECT compid, compname FROM company WHERE comptype=3 ORDER BY compname";
$sth = $pdo->query($sql);
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
$opt_shipyard[$row[0]] = $row[1];
}
$sql = "SELECT vesselname, vtype, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
. " shipyard, sid_default, remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
$sth->execute([$user->vid]);
$vessel = $sth->fetch(PDO::FETCH_OBJ);
?>
=_('Edit Yacht')?>
\n";
else:
// ========== ERROR UNKNOWN VARIANT ===========================================
echo '', _('Unknown function call: Please report to system development!'), "
\n";
endif; // $action == ...
// ========== END OF VARIANTS =================================================
include 'footer.php';