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 '
', _('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"; // 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 = <<| =_('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')?> |
| ', _('Storage type') , " | "; foreach ($res as $row) { echo "|
| ", $stype[$row[0]], " | ", $row[1], " |
| ', _('Boxes'), ' | ', $sth->fetchColumn(), " |
| ', _('Equipment') , " | "; echo '|
| ', _('Count'), ' | ', $sth->fetchColumn(), " |
| ', _('Inventory') , " | "; echo '|
| ', _('Count'), ' | ', $sth->fetchColumn(), " |
', _('Unknown function call: Please report to system development!'), "
\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';