-
Notifications
You must be signed in to change notification settings - Fork 7
/
getHoaConfigList.php
82 lines (72 loc) · 3.16 KB
/
getHoaConfigList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*==============================================================================
* (C) Copyright 2016,2020 John J Kauflin, All rights reserved.
*----------------------------------------------------------------------------
* DESCRIPTION:
*----------------------------------------------------------------------------
* Modification History
* 2016-05-17 JJK Initial version to get config list
* 2020-08-01 JJK Re-factored to use jjklogin for authentication
* 2020-12-21 JJK Re-factored to use jjklogin package
* 2023-02-17 JJK Refactor for non-static jjklogin class and settings from DB
*============================================================================*/
// Define a super global constant for the log file (this will be in scope for all functions)
define("LOG_FILE", "./php.log");
require_once 'vendor/autoload.php';
// Figure out how many levels up to get to the "public_html" root folder
$webRootDirOffset = substr_count(strstr(dirname(__FILE__),"public_html"),DIRECTORY_SEPARATOR) + 1;
// Get settings and credentials from a file in a directory outside of public_html
// (assume a settings file in the "external_includes" folder one level up from "public_html")
$extIncludePath = dirname(__FILE__, $webRootDirOffset+1).DIRECTORY_SEPARATOR.'external_includes'.DIRECTORY_SEPARATOR;
require_once $extIncludePath.'hoadbSecrets.php';
require_once $extIncludePath.'jjkloginSettings.php';
// Common functions
require_once 'php_secure/commonUtil.php';
// Common database functions and table record classes
require_once 'php_secure/hoaDbCommon.php';
use \jkauflin\jjklogin\LoginAuth;
try {
$loginAuth = new LoginAuth($hostJJKLogin, $dbadminJJKLogin, $passwordJJKLogin, $dbnameJJKLogin);
$userRec = $loginAuth->getUserRec();
if ($userRec->userName == null || $userRec->userName == '') {
throw new Exception('User is NOT logged in', 500);
}
if ($userRec->userLevel < 1) {
throw new Exception('User is NOT authorized (contact Administrator)', 500);
}
// If they are set, get input parameters from the REQUEST
$configName = getParamVal("ConfigName");
// Get a connection to the database
$conn = getConn($host, $dbadmin, $password, $dbname);
if (!empty($configName)) {
$sql = "SELECT * FROM hoa_config WHERE ConfigName = ? ";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $configName);
} else {
$sql = "SELECT * FROM hoa_config ORDER BY ConfigName ";
$stmt = $conn->prepare($sql);
}
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
$outputArray = array();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (!empty($row['ConfigName'])) {
//error_log(date('[Y-m-d H:i] '). "in " . basename(__FILE__,".php") . ", $i = " . $row['ConfigName'] . PHP_EOL, 3, LOG_FILE);
array_push($outputArray,$row);
}
}
}
$conn->close();
echo json_encode($outputArray);
} catch(Exception $e) {
//error_log(date('[Y-m-d H:i] '). "in " . basename(__FILE__,".php") . ", Exception = " . $e->getMessage() . PHP_EOL, 3, LOG_FILE);
echo json_encode(
array(
'error' => $e->getMessage(),
'error_code' => $e->getCode()
)
);
}
?>