'SET NAMES utf8')); ORM::configure('return_result_sets', true); if ($_app_stage != 'Live') { ORM::configure('logging', true); } $result = ORM::for_table('tbl_appconfig')->find_many(); foreach ($result as $value) { $config[$value['setting']] = $value['value']; } date_default_timezone_set($config['timezone']); $_c = $config; // check if proxy setup in database if (empty($http_proxy) && !empty($config['http_proxy'])) { $http_proxy = $config['http_proxy']; if (empty($http_proxyauth) && !empty($config['http_proxyauth'])) { $http_proxyauth = $config['http_proxyauth']; } } if ((!empty($radius_user) && $config['radius_enable']) || _post('radius_enable')) { ORM::configure("mysql:host=$radius_host;dbname=$radius_name", null, 'radius'); ORM::configure('username', $radius_user, 'radius'); ORM::configure('password', $radius_pass, 'radius'); ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), 'radius'); ORM::configure('return_result_sets', true, 'radius'); } } catch (Throwable $e) { $ui = new Smarty(); $ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'default' => File::pathFixer('ui/ui/')]); $ui->assign('_url', APP_URL . '/index.php?_route='); $ui->setCompileDir(File::pathFixer('ui/compiled/')); $ui->setConfigDir(File::pathFixer('ui/conf/')); $ui->setCacheDir(File::pathFixer('ui/cache/')); $ui->assign("error_title", "PHPNuxBill Crash"); if (_auth()) { $ui->assign("error_message", $e->getMessage() . '
'); } else { $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); } $ui->display('router-error.tpl'); die(); } catch (Exception $e) { $ui = new Smarty(); $ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'default' => File::pathFixer('ui/ui/')]); $ui->assign('_url', APP_URL . '/index.php?_route='); $ui->setCompileDir(File::pathFixer('ui/compiled/')); $ui->setConfigDir(File::pathFixer('ui/conf/')); $ui->setCacheDir(File::pathFixer('ui/cache/')); $ui->assign("error_title", "PHPNuxBill Crash"); if (_auth()) { $ui->assign("error_message", $e->getMessage() . '
'); } else { $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); } $ui->display('router-error.tpl'); die(); } function _notify($msg, $type = 'e') { $_SESSION['ntype'] = $type; $_SESSION['notify'] = $msg; } if (empty($config['language'])) { $config['language'] = 'english'; } if (empty($_SESSION['Lang'])) { $lan_file = File::pathFixer('system/lan/' . $config['language'] . '.json'); if (file_exists($lan_file)) { $_L = json_decode(file_get_contents($lan_file), true); } else { $_L['nux_created_by'] = 'Auto Generated by iBNuX Script'; $_SESSION['Lang'] = $_L; if (file_exists($lan_file)) { file_put_contents(File::pathFixer('system/lan/' . $config['language'] . '/common.lan.json'), json_encode($_L)); } } } else { $_L = $_SESSION['Lang']; } $ui = new Smarty(); $ui->assign('_kolaps', $_COOKIE['kolaps']); if (!empty($config['theme']) && $config['theme'] != 'default') { $_theme = APP_URL . '/ui/themes/' . $config['theme']; $ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'theme' => File::pathFixer('ui/themes/' . $config['theme']), 'default' => File::pathFixer('ui/ui/')]); } else { $_theme = APP_URL . '/ui/ui'; $ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'default' => File::pathFixer('ui/ui/')]); } $ui->assign('_theme', $_theme); $ui->addTemplateDir(File::pathFixer('system/paymentgateway/ui/'), 'pg'); $ui->addTemplateDir(File::pathFixer('system/plugin/ui/'), 'plugin'); $ui->setCompileDir(File::pathFixer('ui/compiled/')); $ui->setConfigDir(File::pathFixer('ui/conf/')); $ui->setCacheDir(File::pathFixer('ui/cache/')); $ui->assign('app_url', APP_URL); $ui->assign('_domain', str_replace('www.', '', parse_url(APP_URL, PHP_URL_HOST))); define('U', APP_URL . '/index.php?_route='); $ui->assign('_url', APP_URL . '/index.php?_route='); $ui->assign('_path', __DIR__); $ui->assign('_c', $config); $ui->assign('_L', $_L); $ui->assign('_system_menu', 'dashboard'); $ui->assign('_title', $config['CompanyName']); function _msglog($type, $msg) { $_SESSION['ntype'] = $type; $_SESSION['notify'] = $msg; } if (isset($_SESSION['notify'])) { $notify = $_SESSION['notify']; $ntype = $_SESSION['ntype']; $ui->assign('notify', $notify); $ui->assign('notify_t', $ntype); unset($_SESSION['notify']); unset($_SESSION['ntype']); } include "autoload/Hookers.php"; // notification message if (file_exists(File::pathFixer("system/uploads/notifications.json"))) { $_notifmsg = json_decode(file_get_contents(File::pathFixer('system/uploads/notifications.json')), true); } $_notifmsg_default = json_decode(file_get_contents(File::pathFixer('system/uploads/notifications.default.json')), true); //register all plugin foreach (glob(File::pathFixer("system/plugin/*.php")) as $filename) { try { include $filename; } catch (Throwable $e) { } catch (Exception $e) { } } function _auth($login = true) { if (User::getID()) { return true; } else { if ($login) { r2(U . 'login'); } else { return false; } } } function _admin($login = true) { if (Admin::getID()) { return true; } else { if ($login) { r2(U . 'login'); } else { return false; } } } function _log($description, $type = '', $userid = '0') { $d = ORM::for_table('tbl_logs')->create(); $d->date = date('Y-m-d H:i:s'); $d->type = $type; $d->description = $description; $d->userid = $userid; $d->ip = $_SERVER["REMOTE_ADDR"]; $d->save(); } function Lang($key) { return Lang::T($key); } function alphanumeric($str, $tambahan = "") { return preg_replace("/[^a-zA-Z0-9" . $tambahan . "]+/", "", $str); } function sendTelegram($txt) { Message::sendTelegram($txt); } function sendSMS($phone, $txt) { Message::sendSMS($phone, $txt); } function sendWhatsapp($phone, $txt) { Message::sendWhatsapp($phone, $txt); } function time_elapsed_string($datetime, $full = false) { $now = new DateTime; $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array( 'y' => 'year', 'm' => 'month', 'w' => 'week', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second', ); foreach ($string as $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) $string = array_slice($string, 0, 1); return $string ? implode(', ', $string) . ' ago' : 'just now'; } // Routing Engine $req = _get('_route'); $routes = explode('/', $req); $ui->assign('_routes', $routes); $handler = $routes[0]; if ($handler == '') { $handler = 'default'; } try { $sys_render = File::pathFixer('system/controllers/' . $handler . '.php'); if (file_exists($sys_render)) { $menus = array(); // "name" => $name, // "admin" => $admin, // "position" => $position, // "function" => $function $ui->assign('_system_menu', $routes[0]); foreach ($menu_registered as $menu) { if ($menu['admin'] && _admin(false)) { $menus[$menu['position']] .= ''; if (!empty($menu['icon'])) { $menus[$menu['position']] .= ''; } if (!empty($menu['label'])) { $menus[$menu['position']] .= ''; $menus[$menu['position']] .= '' . $menu['label'] . ''; } $menus[$menu['position']] .= '' . $menu['name'] . ''; } else if (!$menu['admin'] && _auth(false)) { $menus[$menu['position']] .= ''; if (!empty($menu['icon'])) { $menus[$menu['position']] .= ''; } if (!empty($menu['label'])) { $menus[$menu['position']] .= ''; $menus[$menu['position']] .= '' . $menu['label'] . ''; } $menus[$menu['position']] .= '' . $menu['name'] . ''; } } foreach ($menus as $k => $v) { $ui->assign('_MENU_' . $k, $v); } unset($menus, $menu_registered); include($sys_render); } else { r2(U . 'dashboard', 'e', 'not found'); } } catch (Throwable $e) { if (!Admin::getID()) { r2(U . 'home', 'e', $e->getMessage()); } $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); $ui->assign("error_title", "PHPNuxBill Crash"); $ui->display('router-error.tpl'); die(); } catch (Exception $e) { if (!Admin::getID()) { r2(U . 'home', 'e', $e->getMessage()); } $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); $ui->assign("error_title", "PHPNuxBill Crash"); $ui->display('router-error.tpl'); die(); }