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); $keys = array_keys($p); $fields = join(',', array_map(function($s) { return ltrim($s, ':'); }, $keys)); $pnames = join(',', $keys); $sth = $pdo->prepare("INSERT INTO vessel ($fields) VALUES ($pnames)"); try { $sth->execute($p); } catch (PDOException $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); } $id = $pdo->LastInsertId(); // 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'), $vid)); $user->load_vessel(); break; case 'update': if ($user->role != 'captain') { $g_error->Add(_('Access denied. You are not the captain.')); break; } // $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); $fields = join(',', array_map(function($s) { return ltrim($s, ':') . '=' . $s; }, array_keys($p))); $sth = $pdo->prepare("UPDATE vessel SET $fields WHERE vid=:vid"); $p[':vid'] = gpc_get_int($_POST, 'id'); try { $sth->execute($p); } catch (PDOException $e) { $g_error->Add('SQL-Error: '. $e->getMessage()); } $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 '

', _('Yacht data'), "

\n"; 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]); // Switch between vessels $sth = $pdo->query("SELECT vid, vesselname, model FROM vessel ORDER BY vid"); $res = $sth->fetchAll(); echo '
', "\n"; echo '
', "\n"; echo ''; echo "
\n"; echo '
', "\n"; echo '\n"; echo "
\n"; echo '
', "\n"; echo '', "\n"; echo '', "\n"; echo "
\n"; echo "
\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 // TODO predefine base shapes for different vessels $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); $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', '100'); $line->addAttribute('style', 'stroke:#ff0000;stroke-width:0.25px'); // rectangle for storage $rect = $g->addChild('rect'); $rect->addAttribute('x', '2'); $rect->addAttribute('y', '14'); $rect->addAttribute('width', '20'); $rect->addAttribute('height', '26'); $rect->addAttribute('stroke', '#000'); $rect->addAttribute('stroke-width', '0.25px'); $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', '3.5'); $text->addAttribute('x', '4'); $text->addAttribute('y', '18'); ?>
asXML()?>
 kg
 kg
role == 'captain') { echo '', _('Edit'), "\n"; } ?>
_('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 '"; foreach ($res as $row) { echo "\n"; } // Boxes $sth = $pdo->prepare("SELECT COUNT(*) FROM box INNER JOIN storage USING (sid) WHERE vid=?"); $sth->execute([$user->vid]); echo '\n"; // Equipment $sth = $pdo->prepare("SELECT COUNT(*) FROM equipment WHERE vid=?"); $sth->execute([$user->vid]); echo '"; echo '\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 '"; echo '\n"; echo "
', _('Storage type') , "
", $stype[$row[0]], "", $row[1], "
', _('Boxes'), '', $sth->fetchColumn(), "
', _('Equipment') , "
', _('Count'), '', $sth->fetchColumn(), "
', _('Inventory') , "
', _('Count'), '', $sth->fetchColumn(), "
\n"; ?>

', _('Add additional yacht'), "\n"; ?>
prepare($sql); $sth->execute([$user->vid]); $vessel = $sth->fetch(PDO::FETCH_OBJ); ?>

vid); echo "
\n"; else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '

', _('Unknown function call: Please report to system development!'), "

\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';