More webgui code improvements and some new vessel data
This commit is contained in:
1 parent
72571ede53
commit
3a43f749f5
13 files changed
+398
-306
No files matched your search
@@ -8,6 +8,8 @@
|
||||
|
||||
*/
|
||||
|
||||
// ========== GENERIC FUNCTIONS ===============================================
|
||||
|
||||
function db_get_setting($sno, $userid, $autocreate=false, $default=NULL) {
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
@@ -36,6 +38,285 @@ function db_get_setting($sno, $userid, $autocreate=false, $default=NULL) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
function db_get_ddtext($ddid, $ddval) {
|
||||
// returns single value for dropdown
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
$sql = "SELECT ddtext FROM dropdown WHERE ddid=? AND ddval=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute([$ddid, $ddval]);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
return '#err';
|
||||
}
|
||||
return $sth->fetchColumn();
|
||||
}
|
||||
|
||||
// ========== OPTION FUNCTIONS ================================================
|
||||
|
||||
// Functions to get option lists (key/value)
|
||||
|
||||
function db_get_options($ddid, $orderby = '', $short = False, $default = NULL) {
|
||||
// returns list for dropdown
|
||||
// if short is set the short value will be returned
|
||||
global $pdo;
|
||||
$list = array();
|
||||
if ($default != NULL) {
|
||||
$list[0] = $default;
|
||||
}
|
||||
if ($short) {
|
||||
$sql = "SELECT ddval, ddshort";
|
||||
} else {
|
||||
$sql = "SELECT ddval, ddtext";
|
||||
}
|
||||
$sql .= " FROM dropdown WHERE ddid=?";
|
||||
if ($orderby == 'ddtext') {
|
||||
$sql .= ' ORDER BY ddtext';
|
||||
} elseif ($orderby == 'sort') {
|
||||
$sql .= ' ORDER BY sort';
|
||||
} else {
|
||||
$sql .= ' ORDER BY ddval';
|
||||
}
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$ddid]);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
$list[$rec[0]] = h($rec[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_vessel() {
|
||||
global $pdo;
|
||||
$list = array();
|
||||
$sth = $pdo->query("SELECT vid, vesselname, model FROM vessel ORDER BY vid");
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
|
||||
$list[$row[0]] = h($row[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_storage($vid) {
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
$list = array();
|
||||
// exclude storage type "tank" from list
|
||||
$sql = "SELECT sid, sname FROM storage WHERE vid=? AND stype<>1 ORDER BY sname";
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute([$vid]);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
}
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
$list[$rec[0]] = h($rec[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_box($vid, $exclude=[]) {
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
$list = array();
|
||||
$sql = "SELECT boxid, label, content "
|
||||
. "FROM box INNER JOIN storage USING (sid) "
|
||||
. "WHERE vid=? "
|
||||
. "ORDER BY label";
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute([$vid]);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
}
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
if (! in_array($rec[0], $exclude)) {
|
||||
$list[$rec[0]] = h($rec[1]) . ($rec[2] ? ' - '. h($rec[2]) : '');
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_equip($vid, $default=NULL, $exclude=[]) {
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
if (isset($default)) {
|
||||
$list = $default;
|
||||
} else {
|
||||
$list = array();
|
||||
}
|
||||
$sql = "SELECT eid, ename FROM equipment WHERE vid=? ORDER BY ename";
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute([$vid]);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
}
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
if (! in_array($rec[0], $exclude)) {
|
||||
$list[$rec[0]] = h($rec[1]);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_manuf($default=NULL) {
|
||||
global $pdo;
|
||||
if (isset($default)) {
|
||||
$list = $default;
|
||||
} else {
|
||||
$list = array();
|
||||
}
|
||||
$sql = "SELECT compid, compname FROM company WHERE comptype=2 ORDER BY compname";
|
||||
$sth = $pdo->query($sql);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
|
||||
$list[$row[0]] = h($row[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_supp($default=NULL) {
|
||||
global $pdo;
|
||||
if (isset($default)) {
|
||||
$list = $default;
|
||||
} else {
|
||||
$list = array();
|
||||
}
|
||||
$sql = "SELECT compid, compname FROM company WHERE comptype=1 ORDER BY compname";
|
||||
$sth = $pdo->query($sql);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
|
||||
$list[$row[0]] = h($row[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_user($default=NULL) {
|
||||
global $pdo;
|
||||
if (isset($default)) {
|
||||
$list = $default;
|
||||
} else {
|
||||
$list = array();
|
||||
}
|
||||
$sql = "SELECT userid, displayname FROM user WHERE userid>0 ORDER BY displayname";
|
||||
$sth = $pdo->query($sql);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
|
||||
$list[$row[0]] = h($row[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_proj($vid, $exclude=[], $default=NULL) {
|
||||
// exclude is a list of project states
|
||||
global $pdo;
|
||||
global $g_error;
|
||||
if (isset($default)) {
|
||||
$list = $default;
|
||||
} else {
|
||||
$list = array();
|
||||
}
|
||||
$sql = "SELECT projid, projname FROM project WHERE vid=?";
|
||||
$where = [];
|
||||
foreach ($exclude as $excl) {
|
||||
$where[] = "NOT FIND_IN_SET('$excl',projstate)";
|
||||
}
|
||||
if (! empty($where)) {
|
||||
$sql .= ' AND '. implode(' AND ', $where);
|
||||
}
|
||||
$sql .= " ORDER BY projname";
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute([$vid]);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
}
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) {
|
||||
$list[$rec[0]] = h($rec[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
function db_get_opt_cable($vid, $default=NULL) {
|
||||
global $pdo;
|
||||
if (isset($default)) {
|
||||
$list = $default;
|
||||
} else {
|
||||
$list = array();
|
||||
}
|
||||
$sql = "SELECT cableid, cablename FROM cable WHERE vid=? ORDER BY cablename";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$vid]);
|
||||
foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
|
||||
$list[$row[0]] = h($row[1]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
// ========== FILTER FUNCTIONS ================================================
|
||||
|
||||
function db_get_filter($user, $sno, $fields = []) {
|
||||
// if fields supplied empting missing field are created
|
||||
global $pdo;
|
||||
global $g_warning;
|
||||
$flt = new stdClass();
|
||||
$sth = $pdo->prepare("SELECT valstr FROM settings WHERE userid=? AND sno=?");
|
||||
try {
|
||||
$sth->execute([$user, $sno]);
|
||||
$json = $sth->fetchColumn();
|
||||
if ($json === false) {
|
||||
// no settings record. create empty one for later updates
|
||||
$sth = $pdo->prepare("INSERT INTO settings (userid, sno, valstr) VALUES (?, ?, '{}')");
|
||||
$sth->execute([$user, $sno]);
|
||||
} else {
|
||||
$flt = json_decode($json);
|
||||
}
|
||||
// create missing fields
|
||||
foreach ($fields as $f) {
|
||||
if (!property_exists($flt, $f)) {
|
||||
$flt->$f = null;
|
||||
}
|
||||
}
|
||||
} catch (PDOexception $e) {
|
||||
$g_warning->Add('SQL-Error: '. $e->getMessage());
|
||||
$g_warning->PrintOut();
|
||||
}
|
||||
return $flt;
|
||||
}
|
||||
|
||||
function db_clear_filter($sno) {
|
||||
global $user;
|
||||
global $pdo;
|
||||
$sql = "DELETE FROM settings WHERE userid=? AND sno=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute([$user->id, $sno]);
|
||||
} catch (PDOexception $e) {
|
||||
$g_warning->Add('SQL-Error: '. $e->getMessage());
|
||||
$g_warning->Add($sql);
|
||||
$g_warning->Add('Setting: ', $sno);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function db_save_filter($flt, $sno) {
|
||||
global $user;
|
||||
global $pdo;
|
||||
global $g_warning;
|
||||
$sql = "UPDATE settings SET valstr=? WHERE userid=? AND sno=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute([json_encode($flt), $user->id, $sno]);
|
||||
} catch (PDOexception $e) {
|
||||
$g_warning->Add('SQL-Error: '. $e->getMessage());
|
||||
$g_warning->Add($sql);
|
||||
$g_warning->Add(print_r($flt, true));
|
||||
$g_warning->Add('Setting: ', $sno);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ========== LOCKING FUNCTIONS ===============================================
|
||||
|
||||
function db_lock_acquire($table, $key, $userid) {
|
||||
global $pdo;
|
||||
$token = bin2hex(random_bytes(8));
|
||||
|
||||
Reference in new issue
Block a user