Merge branch 'master' into techbar
This commit is contained in:
107
functions.php
107
functions.php
@@ -103,7 +103,7 @@ function getIP()
|
||||
|
||||
function getWebBrowser($user_browser)
|
||||
{
|
||||
$browser = "Unknown Browser";
|
||||
$browser = "-";
|
||||
$browser_array = array(
|
||||
'/msie/i' => "<i class='fab fa-fw fa-internet-explorer text-secondary'></i> Internet Explorer",
|
||||
'/firefox/i' => "<i class='fab fa-fw fa-firefox text-secondary'></i> Firefox",
|
||||
@@ -123,7 +123,7 @@ function getWebBrowser($user_browser)
|
||||
|
||||
function getOS($user_os)
|
||||
{
|
||||
$os_platform = "Unknown OS";
|
||||
$os_platform = "-";
|
||||
$os_array = array(
|
||||
'/windows/i' => "<i class='fab fa-fw fa-windows text-secondary'></i> Windows",
|
||||
'/macintosh|mac os x/i' => "<i class='fab fa-fw fa-apple text-secondary'></i> MacOS",
|
||||
@@ -215,7 +215,7 @@ function formatPhoneNumber($phoneNumber)
|
||||
return $phoneNumber;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$phoneNumber = $phoneNumber ? preg_replace('/[^0-9]/', '', $phoneNumber) : "";
|
||||
|
||||
if (strlen($phoneNumber) > 10) {
|
||||
@@ -733,6 +733,16 @@ function sanitizeInput($input)
|
||||
{
|
||||
global $mysqli;
|
||||
|
||||
if (!empty($input)) {
|
||||
// Detect encoding
|
||||
$encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1', 'Windows-1252', 'ISO-8859-15'], true);
|
||||
|
||||
// If not UTF-8, convert to UTF8 (primarily Windows-1252 is problematic)
|
||||
if ($encoding !== 'UTF-8') {
|
||||
$input = mb_convert_encoding($input, 'UTF-8', $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove HTML and PHP tags
|
||||
$input = strip_tags((string) $input);
|
||||
|
||||
@@ -915,43 +925,6 @@ function getTotalTax($tax_name, $year, $mysqli)
|
||||
return $row['total_tax'] ?? 0;
|
||||
}
|
||||
|
||||
//Get account currency code
|
||||
function getAccountCurrencyCode($mysqli, $account_id)
|
||||
{
|
||||
$sql = mysqli_query($mysqli, "SELECT account_currency_code FROM accounts WHERE account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
return nullable_htmlentities($row['account_currency_code']);
|
||||
}
|
||||
|
||||
function calculateAccountBalance($mysqli, $account_id)
|
||||
{
|
||||
$sql_account = mysqli_query($mysqli, "SELECT * FROM accounts LEFT JOIN account_types ON accounts.account_type = account_types.account_type_id WHERE account_archived_at IS NULL AND account_id = $account_id ORDER BY account_name ASC; ");
|
||||
$row = mysqli_fetch_array($sql_account);
|
||||
$opening_balance = floatval($row['opening_balance']);
|
||||
$account_id = intval($row['account_id']);
|
||||
|
||||
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql_payments);
|
||||
$total_payments = floatval($row['total_payments']);
|
||||
|
||||
$sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE revenue_account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql_revenues);
|
||||
$total_revenues = floatval($row['total_revenues']);
|
||||
|
||||
$sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE expense_account_id = $account_id");
|
||||
$row = mysqli_fetch_array($sql_expenses);
|
||||
$total_expenses = floatval($row['total_expenses']);
|
||||
|
||||
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
|
||||
|
||||
if ($balance == '') {
|
||||
$balance = '0.00';
|
||||
}
|
||||
|
||||
return $balance;
|
||||
}
|
||||
|
||||
|
||||
function generateReadablePassword($security_level)
|
||||
{
|
||||
// Cap security level at 5
|
||||
@@ -1149,7 +1122,7 @@ function fetchUpdates() {
|
||||
$updates->latest_version = $latest_version;
|
||||
$updates->update_message = $update_message;
|
||||
|
||||
|
||||
|
||||
return $updates;
|
||||
|
||||
}
|
||||
@@ -1330,7 +1303,55 @@ function enforceUserPermission($module, $check_access_level = 1) {
|
||||
if (!$permitted_access_level || $permitted_access_level < $check_access_level) {
|
||||
$_SESSION['alert_type'] = "danger";
|
||||
$_SESSION['alert_message'] = WORDING_ROLECHECK_FAILED;
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
exit(WORDING_ROLECHECK_FAILED);
|
||||
$map = [
|
||||
"1" => "read",
|
||||
"2" => "write",
|
||||
"3" => "full"
|
||||
];
|
||||
exit(WORDING_ROLECHECK_FAILED . "<br>Tell your admin: $map[$check_access_level] access to $module is not permitted for your role.");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Probably remove this
|
||||
function enforceAdminPermission() {
|
||||
global $session_is_admin;
|
||||
if (!isset($session_is_admin) || !$session_is_admin) {
|
||||
exit(WORDING_ROLECHECK_FAILED . "<br>Tell your admin: Your role does not have admin access.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function customAction($trigger, $entity) {
|
||||
chdir(dirname(__FILE__));
|
||||
if (file_exists(__DIR__ . "/xcustom/xcustom_action_handler.php")) {
|
||||
include_once __DIR__ . "/xcustom/xcustom_action_handler.php";
|
||||
}
|
||||
}
|
||||
|
||||
function appNotify($type, $details, $action = null, $client_id = 0, $entity_id = 0) {
|
||||
global $mysqli;
|
||||
|
||||
if (is_null($action)) {
|
||||
$action = "NULL"; // Without quotes for SQL NULL
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT user_id FROM users
|
||||
WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL
|
||||
");
|
||||
|
||||
while ($row = mysqli_fetch_array($sql)) {
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = '$type', notification = '$details', notification_action = '$action', notification_client_id = $client_id, notification_entity_id = $entity_id, notification_user_id = $user_id");
|
||||
}
|
||||
}
|
||||
|
||||
function logAction($type, $action, $description, $client_id = 0, $entity_id = 0) {
|
||||
global $mysqli, $session_user_agent, $session_ip, $session_user_id;
|
||||
|
||||
if (empty($session_user_id)) {
|
||||
$session_user_id = 0;
|
||||
}
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = '$type', log_action = '$action', log_description = '$description', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $entity_id");
|
||||
}
|
||||
Reference in New Issue
Block a user