fixing PHP warnings

This commit is contained in:
Jokob-sk
2022-12-24 21:57:43 +11:00
parent da3ac55122
commit 0714aea30d
17 changed files with 213 additions and 79 deletions

View File

@@ -9,12 +9,38 @@
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
$configFolderPath = "/home/pi/pialert/config/";
$config_file = "pialert.conf";
$logFolderPath = "/home/pi/pialert/front/log/";
$log_file = "pialert_front.log";
$fullConfPath = $configFolderPath.$config_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
}
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
//------------------------------------------------------------------------------
// DB File Path

View File

@@ -7,24 +7,54 @@
//------------------------------------------------------------------------------
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
// ###################################
// ## TimeZone processing start
// ###################################
foreach (glob("../../../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
$configFolderPath = "/home/pi/pialert/config/";
$config_file = "pialert.conf";
$logFolderPath = "/home/pi/pialert/front/log/";
$log_file = "pialert_front.log";
$fullConfPath = $configFolderPath.$config_file;
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timeZone = "";
foreach ($config_file_lines as $line)
{
if( preg_match('/TIMEZONE(.*?)/', $line, $match) == 1 )
{
if (preg_match('/\'(.*?)\'/', $line, $match) == 1) {
$timeZone = $match[1];
}
}
}
if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
if($timeZone == "")
{
$timeZone = "Europe/Berlin";
}
date_default_timezone_set($timeZone);
$date = new DateTime("now", new DateTimeZone($timeZone) );
$timestamp = $date->format('Y-m-d_H-i-s');
// ###################################
// ## TimeZone processing end
// ###################################
//------------------------------------------------------------------------------
// External files
require 'db.php';
require 'util.php';
require '../templates/language/'.$pia_lang_selected.'.php';
require 'util.php';
//------------------------------------------------------------------------------
// Action selector

View File

@@ -7,14 +7,6 @@
//------------------------------------------------------------------------------
// Puche 2021 pi.alert.application@gmail.com GNU GPLv3
//------------------------------------------------------------------------------
// ## TimeZone processing
$config_file = "../../../config/pialert.conf";
$config_file_lines = file($config_file);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
date_default_timezone_set($Pia_TimeZone);
//------------------------------------------------------------------------------
// External files
require 'db.php';

View File

@@ -44,6 +44,7 @@ function getParameter() {
$parameter = $_REQUEST['parameter'];
$sql = 'SELECT par_Value FROM Parameters
WHERE par_ID="'. quotes($_REQUEST['parameter']) .'"';
$result = $db->query($sql);
$row = $result -> fetchArray (SQLITE3_NUM);
$value = $row[0];

View File

@@ -19,12 +19,8 @@ $log_file = "pialert_front.log";
$fullConfPath = $configFolderPath.$config_file;
chmod($fullConfPath, 0777);
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
$timeZone = "";
@@ -52,11 +48,38 @@ $timestamp = $date->format('Y-m-d_H-i-s');
// ###################################
// ## TimeZone processing end
// ###################################
// ###################################
// ## GUI settings processing start
// ###################################
if (file_exists('../db/setting_darkmode')) {
$ENABLED_DARKMODE = True;
}
foreach (glob("../db/setting_skin*") as $filename) {
$pia_skin_selected = str_replace('setting_','',basename($filename));
}
if (isset($pia_skin_selected) == FALSE or (strlen($pia_skin_selected) == 0)) {$pia_skin_selected = 'skin-blue';}
foreach (glob("../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
require '/home/pi/pialert/front/php/templates/language/'.$pia_lang_selected.'.php';
// ###################################
// ## GUI settings processing end
// ###################################
$FUNCTION = [];
$SETTINGS = [];
$FUNCTION = $_REQUEST['function'];
$SETTINGS = $_REQUEST['settings'];
if(array_search('function', $FUNCTION) != FALSE)
{
$FUNCTION = $_REQUEST['function'];
}
if(array_search('function', $SETTINGS) != FALSE)
{
$SETTINGS = $_REQUEST['settings'];
}
if ($FUNCTION == 'savesettings') {
saveSettings();
@@ -120,7 +143,7 @@ function formatIPlong ($IP) {
//------------------------------------------------------------------------------
// Others functions
// Other functions
//------------------------------------------------------------------------------
function checkPermissions($files)
{

View File

@@ -13,7 +13,7 @@
<!-- &copy; 2020 Puche -->
<?php
echo '<span style="display:inline-block; transform: rotate(180deg)">&copy;</span> 2020 Puche (+2022 jokob-sk)';
echo '<span style="display:inline-block; transform: rotate(180deg)">&copy;</span> 2020 Puche (2022+ jokob-sk)';
?>
<!-- To the right -->
<div class="pull-right no-hidden-xs">

View File

@@ -20,12 +20,8 @@ $log_file = "pialert_front.log";
$fullConfPath = $configFolderPath.$config_file;
chmod($fullConfPath, 0777);
$config_file_lines = file($fullConfPath);
$config_file_lines_timezone = array_values(preg_grep('/^TIMEZONE\s.*/', $config_file_lines));
$timezone_line = explode("'", $config_file_lines_timezone[0]);
$Pia_TimeZone = $timezone_line[1];
$timeZone = "";
@@ -63,12 +59,12 @@ if (file_exists('../db/setting_darkmode')) {
foreach (glob("../db/setting_skin*") as $filename) {
$pia_skin_selected = str_replace('setting_','',basename($filename));
}
if (strlen($pia_skin_selected) == 0) {$pia_skin_selected = 'skin-blue';}
if (isset($pia_skin_selected) == FALSE or (strlen($pia_skin_selected) == 0)) {$pia_skin_selected = 'skin-blue';}
foreach (glob("../db/setting_language*") as $filename) {
$pia_lang_selected = str_replace('setting_language_','',basename($filename));
}
if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';}
if (isset($pia_lang_selected) == FALSE or (strlen($pia_lang_selected) == 0)) {$pia_lang_selected = 'en_us';}
require 'php/templates/language/'.$pia_lang_selected.'.php';
// ###################################
// ## GUI settings processing end

View File

@@ -474,7 +474,7 @@ $pia_lang['REPORT_WEBHOOK_description'] = 'Enable webhooks for notifications. If
$pia_lang['WEBHOOK_URL_name'] = 'Target URL';
$pia_lang['WEBHOOK_URL_description'] = 'Target URL starting with <code>http://</code> or <code>https://</code>.';
$pia_lang['WEBHOOK_PAYLOAD_name'] = 'Payload type';
$pia_lang['WEBHOOK_PAYLOAD_description'] = 'The Webhook payload data format for the "body > attachements > text" attribute in the payload json. See an examnple of the payload <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/blob/main/docs/webhook_json_sample.json">here</a>. (e.g.: for discord use <code>\'html\'</code>)';
$pia_lang['WEBHOOK_PAYLOAD_description'] = 'The Webhook payload data format for the "body > attachements > text" attribute in the payload json. See an example of the payload <a target="_blank" href="https://github.com/jokob-sk/Pi.Alert/blob/main/docs/webhook_json_sample.json">here</a>. (e.g.: for discord use <code>\'html\'</code>)';
$pia_lang['WEBHOOK_REQUEST_METHOD_name'] = 'Request method';
$pia_lang['WEBHOOK_REQUEST_METHOD_description'] = 'The HTTP request method to be used for the webhook call.';