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
+1
-273
@@ -48,7 +48,7 @@ define('ROLE_CAPTAIN', 'captain');
|
||||
define('ROLE_HELMSMAN', 'helmsman');
|
||||
define('ROLE_SAILOR', 'sailor');
|
||||
|
||||
define('DD_HULL_TYPE', 1);
|
||||
define('DD_VESSEL_TYPE', 1);
|
||||
define('DD_COMPANY_TYPE', 2);
|
||||
define('DD_STORAGE_TYPE', 3);
|
||||
define('DD_EQUIPMENT_CATEGORY', 4);
|
||||
@@ -531,39 +531,6 @@ function db_exec_delete($table, $condition, $params) {
|
||||
return $sth->rowCount();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function get_enum($enum) {
|
||||
// translate and beautify enums
|
||||
@@ -792,245 +759,6 @@ function db_get_tag_target($objtype, $objid) {
|
||||
return [$target, $desc];
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// 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($userid, $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;
|
||||
}
|
||||
|
||||
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_get_default_storage($vesselid, $fallback=true) {
|
||||
global $pdo;
|
||||
global $g_error, $g_warning;
|
||||
|
||||
+22
-14
@@ -13,6 +13,9 @@ require 'lib/svg.inc';
|
||||
|
||||
$pagetitle = _('Start');
|
||||
|
||||
$opt_htype = db_load_enum('vessel', 'htype', true, true);
|
||||
$opt_vtype = db_get_options(DD_VESSEL_TYPE);
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
|
||||
switch ($submit = form_get_action()) {
|
||||
@@ -64,9 +67,10 @@ switch ($submit = form_get_action()) {
|
||||
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[':htype'] = gpc_get_enum($_POST, 'htype', $opt_htype, 'mono');
|
||||
$p[':vtype'] = gpc_get_int($_POST, 'vtype', NULL, -1);
|
||||
$p[':vesselname'] = gpc_get_string($_POST, 'vesselname', 40);
|
||||
$p[':model'] = gpc_get_string($_POST, 'model', 20);
|
||||
$p[':loa'] = gpc_get_float($_POST, 'loa');
|
||||
$p[':lwl'] = gpc_get_float($_POST, 'lwl');
|
||||
$p[':beam'] = gpc_get_float($_POST, 'beam');
|
||||
@@ -76,15 +80,10 @@ switch ($submit = form_get_action()) {
|
||||
$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');
|
||||
if ($p[':shipyard'] == '-1') {
|
||||
$p[':shipyard'] = NULL;
|
||||
}
|
||||
$p[':shapefile'] = gpc_get_string($_POST, 'shapefile', 40, NULL, '-1');
|
||||
$p[':shipyard'] = gpc_get_int($_POST, 'shipyard', NULL, -1);
|
||||
$p[':year_built'] = gpc_get_int($_POST, 'year_built');
|
||||
$p[':hull_number'] = gpc_get_string($_POST, 'hull_number', 20);
|
||||
$p[':sid_default'] = gpc_get_uint($_POST, 'sid');
|
||||
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
|
||||
db_exec_update('vessel', $p, 'vid');
|
||||
@@ -531,9 +530,9 @@ 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,"
|
||||
$sql = "SELECT vesselname, vtype, htype, model, loa, lwl, beam, draught, draught_min,"
|
||||
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
|
||||
. " shipyard, year_built, sid_default, remarks "
|
||||
. " shipyard, year_built, hull_number, sid_default, remarks "
|
||||
. "FROM vessel "
|
||||
. "WHERE vid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -551,6 +550,9 @@ $vessel = $sth->fetch(PDO::FETCH_OBJ);
|
||||
<label for="model" class="form-label"><?=_('Model')?></label>
|
||||
<input type="text" class="form-control" id="model" name="model" value="<?=$vessel->model ?>">
|
||||
</div>
|
||||
<?php
|
||||
form_create_select('vtype', _('Vessel type'), $g_opt_unknown + $opt_vtype, $vessel->vtype);
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="year_built" class="form-label"><?=_('Year built')?></label>
|
||||
<input type="number" class="form-control" id="year_built" name="year_built" value="<?=$vessel->year_built ?>">
|
||||
@@ -596,10 +598,16 @@ $vessel = $sth->fetch(PDO::FETCH_OBJ);
|
||||
<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('htype', _('Hull type'), $opt_htype, $vessel->htype);
|
||||
form_create_select('shapefile', _('Shape file'), $opt_shapefiles, $vessel->shapefile);
|
||||
form_create_select('shipyard', _('Shipyard'), $opt_shipyard, $vessel->shipyard);
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="hull_number" class="form-label"><?=_('Hull number')?></label>
|
||||
<input type="text" class="form-control" id="hull_number" name="hull_number" value="<?=$vessel->hull_number ?>">
|
||||
</div>
|
||||
<?php
|
||||
form_create_select('sid', _('Default Storage'), $g_opt_none + $opt_storage, $vessel->sid_default);
|
||||
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
|
||||
@@ -156,7 +156,7 @@ if (strlen($flt->cond) > 2 ) {
|
||||
$p[':invcond'] = $flt->cond;
|
||||
}
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = 'invname LIKE :txt';
|
||||
$w[] = 'invname LIKE :txt OR i.remarks LIKE :txt';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
}
|
||||
$where = join(' AND ', $w);
|
||||
|
||||
@@ -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));
|
||||
|
||||
+19
-6
@@ -10,24 +10,37 @@
|
||||
|
||||
// ========== GPC FUNCTIONS ===================================================
|
||||
|
||||
function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL) {
|
||||
// TODO Parameter nullval: single value or array of values which considered as null
|
||||
// Default value for nullval is "-1"
|
||||
function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL, $nullvals = []) {
|
||||
// Parameter nullvals: single value or array of values which considered as null
|
||||
if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
|
||||
return $default;
|
||||
}
|
||||
$s = trim($GPC[$varname]);
|
||||
if (isset($maxlen)) {
|
||||
return substr($s, 0, $maxlen);
|
||||
$s = substr($s, 0, $maxlen);
|
||||
}
|
||||
if (!is_array($nullvals)) {
|
||||
$nullvals = [$nullvals];
|
||||
}
|
||||
if (in_array($s, $nullvals, true)) {
|
||||
return NULL;
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
function gpc_get_int(&$GPC, $varname, $default = NULL) {
|
||||
function gpc_get_int(&$GPC, $varname, $default = NULL, $nullvals = []) {
|
||||
// Parameter nullvals: single value or array of values which considered as null
|
||||
if (!isset($GPC[$varname]) || $GPC[$varname] === '') {
|
||||
return $default;
|
||||
}
|
||||
return (int)$GPC[$varname];
|
||||
$value = (int)$GPC[$varname];
|
||||
if (!is_array($nullvals)) {
|
||||
$nullvals = [$nullvals];
|
||||
}
|
||||
if (in_array($value, $nullvals, true)) {
|
||||
return NULL;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function gpc_get_uint(&$GPC, $varname, $default = NULL) {
|
||||
|
||||
@@ -14,12 +14,16 @@ $pagetitle = _('Projects');
|
||||
|
||||
$id = gpc_get_int($_REQUEST, 'id', 0);
|
||||
|
||||
/* OLD
|
||||
$sql = "SELECT userid, displayname FROM user WHERE userid>0";
|
||||
$sth = $pdo->query($sql);
|
||||
$opt_user = array();
|
||||
foreach ($sth->fetchAll() as $row) {
|
||||
$opt_user[$row['userid']] = $row['displayname'];
|
||||
}
|
||||
*/
|
||||
$opt_user = db_get_opt_user();
|
||||
|
||||
$opt_state = db_load_enum('project', 'projstate', true, true);
|
||||
|
||||
/* Nur für choices benötigt
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ $pagetitle = _('Storage');
|
||||
|
||||
$id = gpc_get_int($_REQUEST, 'id', 0);
|
||||
|
||||
$opt_stype = db_get_options(SS_STORAGE_TYPE);
|
||||
$opt_stype = db_get_options(DD_STORAGE_TYPE);
|
||||
$opt_capaunit = $g_opt_empty + db_load_enum('storage', 'capaunit', true, true);
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
|
||||
+1
-1
@@ -352,7 +352,7 @@ echo '<p>', _('Not yet implemented'), "</p>";
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== VARIANT: edit single record =====================================
|
||||
|
||||
$opt_user = db_get_opt_user($user->id); // only used here
|
||||
$opt_user = db_get_opt_user(); // only used here
|
||||
|
||||
$sql = "SELECT taskname, projid, priority, plandate, duedate, started, finished,"
|
||||
. " taskstate "
|
||||
|
||||
Reference in new issue
Block a user