88 lines
3.6 KiB
PHP
Raw Normal View History

<?php
2024-08-19 11:48:06 +07:00
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
_admin();
2022-10-13 14:00:54 +07:00
$ui->assign('_title', 'Pages');
$ui->assign('_system_menu', 'pages');
$action = $routes['1'];
$ui->assign('_admin', $admin);
2024-08-19 11:48:06 +07:00
if (strpos($action, "-reset") !== false) {
2024-02-26 11:01:54 +07:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
2024-08-19 11:48:06 +07:00
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 11:01:54 +07:00
}
2024-08-19 11:48:06 +07:00
$action = str_replace("-reset", "", $action);
2024-08-19 16:13:51 +07:00
$path = "$PAGES_PATH/" . str_replace(".", "", $action) . ".html";
2024-08-19 11:48:06 +07:00
$temp = "pages_template/" . str_replace(".", "", $action) . ".html";
if (file_exists($temp)) {
if (!copy($temp, $path)) {
file_put_contents($path, Http::getData('https://raw.githubusercontent.com/hotspotbilling/phpnuxbill/master/pages_template/' . $action . '.html'));
2023-10-20 10:34:24 +07:00
}
2024-08-19 11:48:06 +07:00
} else {
file_put_contents($path, Http::getData('https://raw.githubusercontent.com/hotspotbilling/phpnuxbill/master/pages_template/' . $action . '.html'));
2023-10-20 10:34:24 +07:00
}
2025-01-31 16:22:58 +07:00
r2(getUrl('pages/') . $action);
2024-08-19 11:48:06 +07:00
} else if (strpos($action, "-post") === false) {
2024-02-26 11:01:54 +07:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
2024-08-19 11:48:06 +07:00
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 11:01:54 +07:00
}
2024-08-19 16:13:51 +07:00
$path = "$PAGES_PATH/" . str_replace(".", "", $action) . ".html";
$ui->assign("action", $action);
//echo $path;
2022-09-18 00:00:40 +07:00
run_hook('view_edit_pages'); #HOOK
2024-08-19 11:48:06 +07:00
if (!file_exists($path)) {
$temp = "pages_template/" . str_replace(".", "", $action) . ".html";
if (file_exists($temp)) {
if (!copy($temp, $path)) {
2023-09-20 14:27:15 +07:00
touch($path);
}
2024-08-19 11:48:06 +07:00
} else {
2023-09-20 14:27:15 +07:00
touch($path);
}
}
2024-08-19 11:48:06 +07:00
if (file_exists($path)) {
if ($action == 'Voucher') {
2024-08-19 16:13:51 +07:00
if (!file_exists("$PAGES_PATH/vouchers/")) {
mkdir("$PAGES_PATH/vouchers/");
2024-08-19 11:48:06 +07:00
if (file_exists("pages_template/vouchers/")) {
2024-08-19 16:13:51 +07:00
File::copyFolder("pages_template/vouchers/", "$PAGES_PATH/vouchers/");
}
}
2024-08-19 16:13:51 +07:00
$ui->assign("vouchers", scandir("$PAGES_PATH/vouchers/"));
}
$html = file_get_contents($path);
2024-08-19 11:48:06 +07:00
$ui->assign("htmls", str_replace(["<div", "</div>"], "", $html));
$ui->assign("writeable", is_writable($path));
$ui->assign("pageHeader", str_replace('_', ' ', $action));
$ui->assign("PageFile", $action);
2025-02-04 10:56:02 +07:00
$ui->display('admin/settings/page.tpl');
2024-08-19 11:48:06 +07:00
} else
2025-02-04 09:23:55 +07:00
$ui->display('admin/404.tpl');
2024-08-19 11:48:06 +07:00
} else {
2024-02-26 11:01:54 +07:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
2024-08-19 11:48:06 +07:00
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-02-26 11:01:54 +07:00
}
2024-08-19 11:48:06 +07:00
$action = str_replace("-post", "", $action);
2024-08-19 16:13:51 +07:00
$path = "$PAGES_PATH/" . str_replace(".", "", $action) . ".html";
2024-08-19 11:48:06 +07:00
if (file_exists($path)) {
$html = _post("html");
2022-09-18 00:00:40 +07:00
run_hook('save_pages'); #HOOK
2024-08-19 11:48:06 +07:00
if (file_put_contents($path, $html)) {
if (_post('template_save') == 'yes') {
if (!empty(_post('template_name'))) {
2024-08-19 16:23:28 +07:00
file_put_contents("$PAGES_PATH/vouchers/" . _post('template_name') . '.html', $html);
}
}
2025-01-31 16:22:58 +07:00
r2(getUrl('pages/') . $action, 's', Lang::T("Saving page success"));
2024-08-19 11:48:06 +07:00
} else {
2025-01-31 16:22:58 +07:00
r2(getUrl('pages/') . $action, 'e', Lang::T("Failed to save page, make sure i can write to folder pages, <i>chmod 664 pages/*.html<i>"));
}
2024-08-19 11:48:06 +07:00
} else
2025-02-04 09:23:55 +07:00
$ui->display('admin/404.tpl');
2024-08-19 11:48:06 +07:00
}