settings prep 0

This commit is contained in:
Jokob-sk
2022-12-19 23:53:48 +11:00
parent 4839c02d50
commit 1ea7990314
10 changed files with 796 additions and 32 deletions

View File

@@ -20,7 +20,6 @@ date_default_timezone_set($Pia_TimeZone);
// DB File Path
$DBFILE = '../../../db/pialert.db';
//------------------------------------------------------------------------------
// Connect DB
//------------------------------------------------------------------------------
@@ -36,9 +35,11 @@ function SQLite3_connect ($trytoreconnect) {
{
// sqlite3 throws an exception when it is unable to connect
// try to reconnect one time after 3 seconds
if($trytoreconnect)
{
sleep(3);
echo '<script>alert("Error connecting to database, will try in 3s")</script>';
sleep(3);
return SQLite3_connect(false);
}
}
@@ -48,21 +49,31 @@ function SQLite3_connect ($trytoreconnect) {
//------------------------------------------------------------------------------
// Open DB
//------------------------------------------------------------------------------
function OpenDB () {
function OpenDB (...$DBPath) {
global $DBFILE;
global $db;
// use custom path if supplied
foreach ($DBPath as $path) {
$DBFILE = $path;
}
if(strlen($DBFILE) == 0)
{
die ('Database no available');
echo '<script>alert("Database not available")</script>';
die ('<div style="padding-left:150px">Database not available</div>');
}
$db = SQLite3_connect(true);
$db->exec('PRAGMA journal_mode = wal;');
if(!$db)
{
die ('Error connecting to database');
echo '<script>alert("Error connecting to the database")</script>';
die ('<div style="padding-left:150px">Error connecting to the database</div>');
}
$db->exec('PRAGMA journal_mode = wal;');
}
?>

View File

@@ -19,6 +19,14 @@ date_default_timezone_set($Pia_TimeZone);
//------------------------------------------------------------------------------
// Formatting data functions
//------------------------------------------------------------------------------
function createArray($input){
$pattern = '/(^\s*\[)|(\]\s*$)/';
$replacement = '';
$noBrackets = preg_replace($pattern, $replacement, $input);
return $options = explode(",", $noBrackets);
}
function formatDate ($date1) {
return date_format (new DateTime ($date1) , 'Y-m-d H:i');
}
@@ -51,6 +59,18 @@ function formatIPlong ($IP) {
//------------------------------------------------------------------------------
// Others functions
//------------------------------------------------------------------------------
function getString ($codeName, $default, $pia_lang) {
$result = $pia_lang[$codeName];
if ($result )
{
return $result;
}
return $default;
}
function getDateFromPeriod () {
$period = $_REQUEST['period'];
return '"'. date ('Y-m-d', strtotime ('+1 day -'. $period) ) .'"';