-
Notifications
You must be signed in to change notification settings - Fork 24
/
boot.php
86 lines (64 loc) · 1.79 KB
/
boot.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
83
84
85
86
<?php
/**
* OpenTHC POS Application Bootstrap
*
* SPDX-License-Identifier: GPL-3.0-only
*/
define('APP_ROOT', __DIR__);
define('APP_SALT', ''); // put 16 to 32 characters here
define('APP_BUILD', '420.24.326');
define('APP_VERSION', '420.24.326');
openlog('openthc-pos', LOG_ODELAY|LOG_PID, LOG_LOCAL0);
error_reporting(E_ALL & ~ E_NOTICE);
// Composer
require_once(APP_ROOT . '/vendor/autoload.php');
if ( ! \OpenTHC\Config::init(APP_ROOT) ) {
_exit_html_fail('<h1>Invalid Application Configuration [POS-017]</h1>', 500);
}
define('OPENTHC_SERVICE_ID', \OpenTHC\Config::get('openthc/pos/id'));
define('OPENTHC_SERVICE_ORIGIN', \OpenTHC\Config::get('openthc/pos/origin'));
_error_handler_init();
/**
* Database Connection
*/
function _dbc($dsn=null)
{
static $dbc_list = [];
if (empty($dsn)) {
$dsn = 'auth';
}
$dbc = $dbc_list[$dsn];
if (!empty($dbc)) {
return $dbc;
}
switch ($dsn) {
case 'auth':
case 'main':
case 'root':
$cfg = \OpenTHC\Config::get(sprintf('database/%s', $dsn));
if (empty($cfg)) {
_exit_text('Invalid Database Configuration [ABD-039]', 500);
}
$dbc_list[$dsn] = new \Edoceo\Radix\DB\SQL(sprintf('pgsql:application_name=openthc-pos;host=%s;dbname=%s', $cfg['hostname'], $cfg['database']), $cfg['username'], $cfg['password']);
return $dbc_list[$dsn];
default:
$dbc_list[$dsn] = new \Edoceo\Radix\DB\SQL($dsn);
return $dbc_list[$dsn];
}
return null;
}
function _draw_html_card($head, $body, $foot=null)
{
ob_start();
echo '<div class="card">';
printf('<div class="card-header">%s</div>', $head);
printf('<div class="card-body">%s</div>', $body);
if ($foot) {
printf('<div class="card-footer">%s</div>', $foot);
}
echo '</div>';
return ob_get_clean();
}
/**
* You can put custom stuff here, it will be available to the entire application
*/