Webgui: ongoing development
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/******************************************************************************
|
||||
* YMS - Yacht Management Software
|
||||
* Copyright (C) 2024 Thomas Hooge
|
||||
* Copyright (C) 2024-2026 Thomas Hooge
|
||||
*
|
||||
* SPDX-License-Identifier: WTFPL
|
||||
******************************************************************************
|
||||
@@ -14,8 +14,16 @@ function file_fix_filesize($docid, $filepath) {
|
||||
// set filesize in database to current size in filesystem
|
||||
global $pdo;
|
||||
$newsize = filesize($filepath);
|
||||
$sth = $pdo->prepare("UPDATE document SET docsize=? WHERE docid=?");
|
||||
$sth->execute([$docid, $newsize]);
|
||||
$sql = "UPDATE document SET docsize=? WHERE docid=?";
|
||||
$params = [$newsize, $docid];
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute($params);
|
||||
} catch (PDOexception $e) {
|
||||
$g_error->Add('SQL-Error: '. $e->getMessage());
|
||||
$g_error->Add($sql);
|
||||
$g_error->Add(print_r($params, true));
|
||||
}
|
||||
return $newsize;
|
||||
}
|
||||
|
||||
@@ -23,3 +31,15 @@ function file_get_docname($docid, $doctype, $extension) {
|
||||
global $g_doc_typemap;
|
||||
return sprintf('%s-%06d.%s', $g_doc_typemap[$doctype], $docid, $extension);
|
||||
}
|
||||
|
||||
function dir_get_size($path) {
|
||||
// gets the size of a directory in bytes recursively
|
||||
$total = 0;
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)
|
||||
);
|
||||
foreach ($iterator as $file){
|
||||
$total += $file->getSize();
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/******************************************************************************
|
||||
* YMS - Yacht Management Software
|
||||
* Copyright (C) 2024-2026 Thomas Hooge
|
||||
*
|
||||
* SPDX-License-Identifier: WTFPL
|
||||
******************************************************************************
|
||||
|
||||
*/
|
||||
|
||||
// ========== 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"
|
||||
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
|
||||
return $default;
|
||||
}
|
||||
$s = trim($GPC[$varname]);
|
||||
if (isset($maxlen)) {
|
||||
return substr($s, 0, $maxlen);
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
function gpc_get_int(&$GPC, $varname, $default = NULL) {
|
||||
if (!isset($GPC[$varname])) {
|
||||
return $default;
|
||||
}
|
||||
return (int)$GPC[$varname];
|
||||
}
|
||||
|
||||
function gpc_get_float(&$GPC, $varname, $default = NULL) {
|
||||
global $g_lconv;
|
||||
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
|
||||
return $default;
|
||||
}
|
||||
$var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]);
|
||||
if ($g_lconv['decimal_point'] != '.') {
|
||||
$var = str_replace($g_lconv['decimal_point'], '.', $var);
|
||||
}
|
||||
return (double)$var;
|
||||
}
|
||||
|
||||
function gpc_get_currency(&$GPC, $varname, $default = NULL) {
|
||||
global $g_lconv;
|
||||
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
|
||||
return $default;
|
||||
}
|
||||
$var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]);
|
||||
if ($g_lconv['decimal_point'] != '.') {
|
||||
$var = str_replace($g_lconv['decimal_point'], '.', $var);
|
||||
}
|
||||
return (double)$var;
|
||||
}
|
||||
|
||||
function gpc_get_bool(&$GPC, $varname, $default = FALSE) {
|
||||
if (!isset($GPC[$varname])) {
|
||||
return $default;
|
||||
}
|
||||
$gpcvar = trim($GPC[$varname]);
|
||||
if (strcasecmp('off', $gpcvar) == 0 ||
|
||||
strcasecmp('no', $gpcvar) == 0 ||
|
||||
strcasecmp('false', $gpcvar) == 0 ||
|
||||
strcasecmp('no', $gpcvar) == 0 ||
|
||||
strcasecmp('0', $gpcvar) == 0 ||
|
||||
strcasecmp('nein', $gpcvar) == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function gpc_get_date(&$GPC, $varname, $default = NULL) {
|
||||
// TODO improve
|
||||
if (!isset($GPC[$varname]) || $GPC[$varname] == '') {
|
||||
return $default;
|
||||
}
|
||||
return $GPC[$varname];
|
||||
}
|
||||
|
||||
function gpc_get_datetime(&$GPC, $varname, $default = NULL) {
|
||||
// TODO improve
|
||||
if (!isset($GPC[$varname]) || $GPC[$varname] == '') {
|
||||
return $default;
|
||||
}
|
||||
return $GPC[$varname];
|
||||
}
|
||||
|
||||
function gpc_get_color(&$GPC, $varname, $default = NULL) {
|
||||
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
|
||||
return $default;
|
||||
}
|
||||
$color = $GPC[$varname];
|
||||
if ((strlen($color) == 7) and (substr($color, 0, 1) == '#')) {
|
||||
$color = substr($color, 1);
|
||||
}
|
||||
if ((strlen($color) != 6) or (! ctype_xdigit($color))) {
|
||||
return $default;
|
||||
}
|
||||
return strtoupper($color);
|
||||
}
|
||||
|
||||
function gpc_get_enum(&$GPC, $varname, $values, $default = NULL) {
|
||||
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
|
||||
return $default;
|
||||
}
|
||||
if (! in_array($GPC[$varname], $values)) {
|
||||
return $default;
|
||||
}
|
||||
return $GPC[$varname];
|
||||
}
|
||||
Reference in New Issue
Block a user