From 259761b5979341701fdd5a4685e8216231004ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Wed, 25 Sep 2024 19:45:42 +0900 Subject: [PATCH] cfmgrv4 innit...1 --- app/Config/Constants.php | 14 +- app/Config/Routes.php | 30 ++-- app/Controllers/Admin/AdminController.php | 21 +++ .../Cloudflare/AccountController.php | 48 ++---- .../Cloudflare/CloudflareController.php | 19 +-- .../Cloudflare/RecordController.php | 33 ++-- .../{ => Admin}/Cloudflare/ZoneController.php | 52 ++----- app/Controllers/CommonController.php | 12 +- app/Controllers/MVController.php | 95 +++--------- app/Entities/Cloudflare/AccountEntity.php | 2 +- app/Entities/Cloudflare/RecordEntity.php | 4 +- app/Entities/Cloudflare/ZoneEntity.php | 2 +- .../Admin/Cloudflare/Account_helper.php | 137 +++++++++++++++++ app/Helpers/Admin/Cloudflare/Zone_helper.php | 67 +++++++++ app/Helpers/Cloudflare/Account_helper.php | 1 - .../en/{ => Admin}/Cloudflare/Account.php | 2 +- .../en/{ => Admin}/Cloudflare/Record.php | 0 .../en/{ => Admin}/Cloudflare/Zone.php | 0 app/Libraries/CommonLibrary.php | 12 +- app/Models/Cloudflare/AccountModel.php | 9 +- app/Models/Cloudflare/ZoneModel.php | 10 +- app/Models/CommonModel.php | 17 ++- .../{ => admin}/cloudflare/account/create.php | 4 +- app/Views/admin/cloudflare/account/index.php | 68 +++++++++ .../{ => admin}/cloudflare/account/update.php | 0 .../{ => admin}/cloudflare/account/view.php | 0 app/Views/cloudflare/account/index.php | 56 ------- app/Views/layouts/admin.php | 14 +- app/Views/layouts/admin/head.php | 36 ++++- .../layouts/admin/head/make_password.php | 5 - app/Views/layouts/admin/head/member_link.php | 17 --- app/Views/layouts/admin/head/search.php | 4 - app/Views/layouts/admin/left_menu.php | 6 +- app/Views/layouts/admin/tail.php | 3 + app/Views/templates/admin/index_head.php | 12 -- public/css/admin.css | 15 +- public/css/admin/content.css | 142 ++++++++---------- 37 files changed, 533 insertions(+), 436 deletions(-) create mode 100644 app/Controllers/Admin/AdminController.php rename app/Controllers/{ => Admin}/Cloudflare/AccountController.php (59%) rename app/Controllers/{ => Admin}/Cloudflare/CloudflareController.php (76%) rename app/Controllers/{ => Admin}/Cloudflare/RecordController.php (80%) rename app/Controllers/{ => Admin}/Cloudflare/ZoneController.php (71%) create mode 100644 app/Helpers/Admin/Cloudflare/Account_helper.php create mode 100644 app/Helpers/Admin/Cloudflare/Zone_helper.php delete mode 100644 app/Helpers/Cloudflare/Account_helper.php rename app/Language/en/{ => Admin}/Cloudflare/Account.php (93%) rename app/Language/en/{ => Admin}/Cloudflare/Record.php (100%) rename app/Language/en/{ => Admin}/Cloudflare/Zone.php (100%) rename app/Views/{ => admin}/cloudflare/account/create.php (81%) create mode 100644 app/Views/admin/cloudflare/account/index.php rename app/Views/{ => admin}/cloudflare/account/update.php (100%) rename app/Views/{ => admin}/cloudflare/account/view.php (100%) delete mode 100644 app/Views/cloudflare/account/index.php delete mode 100644 app/Views/layouts/admin/head/make_password.php delete mode 100644 app/Views/layouts/admin/head/member_link.php delete mode 100644 app/Views/layouts/admin/head/search.php delete mode 100644 app/Views/templates/admin/index_head.php diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 802a43d..f74b31e 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -130,12 +130,7 @@ define('AUTH_FIELDS', [ 'TITLE' => 'title', 'ROLE' => 'role', ]); -//DBAction -define('DB_ACTION', [ - 'CREATE' => 'create', - 'MODIFY' => 'modify', -]); - +//메신저 관련 define("MESSENGERS", [ "skype" => [ "url" => "https://join.skype.com/invite/uKUgXfZThSQC", @@ -158,7 +153,6 @@ define("MESSENGERS", [ "id" => '', ], ]); - //아이콘 및 Sound관련 define('ICONS', [ 'LOGO' => '', @@ -187,7 +181,7 @@ define('ICONS', [ 'IMAGE_FILE' => '', 'GOOGLE' => '', ]); - +//배너관련 define('TOP_BANNER', [ 'default' => '', 'aboutus' => '', @@ -197,11 +191,11 @@ define('TOP_BANNER', [ 'service' => '', 'support' => '', ]); - +//소리관련 define('AUDIOS', [ 'Alram_GetEmail' => '', ]); - +//Layout관련 define('KEYWORD', '일본IDC 일본서버 일본 서버 일본호스팅 서버호스팅 디도스 공격 해외 호스팅 DDOS 방어 ddos 의뢰 디도스 보안 일본 단독서버 가상서버'); define('LAYOUTS', [ 'empty' => [ diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3b13842..4d8c6f4 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -12,23 +12,25 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4} //1. app/Filters/AuthFilter.php //2. Config/Filters.php -> $aliases = ['authFilter' => AuthFilter::class] $routes->get('/', 'Home::index'); -$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) { +// $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) { +$routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function ($routes) { $routes->get('/', 'Home::index'); $routes->group('user', function ($routes) { $routes->get('/', 'UserController::index'); }); -}); -$routes->group('cloudflare', ['namespace' => 'App\Controllers\Cloudflare'], function ($routes) { - $routes->group('account', function ($routes) { - $routes->get('/', 'AccountController::index'); - $routes->post('create', 'AccountController::create'); - }); - $routes->group('zone', function ($routes) { - $routes->get('/', 'ZoneController::index'); - $routes->post('create/(:uuid)', 'RecordController::create/$1'); - }); - $routes->group('record', function ($routes) { - $routes->get('/', 'RecordController::index'); - $routes->post('create/(:uuid)', 'RecordController::create/$1'); + $routes->group('cloudflare', ['namespace' => 'App\Controllers\Admin\Cloudflare'], function ($routes) { + $routes->group('account', function ($routes) { + $routes->get('/', 'AccountController::index'); + $routes->post('create', 'AccountController::create'); + }); + $routes->group('zone', function ($routes) { + $routes->get('/', 'ZoneController::index'); + $routes->post('create/(:uuid)', 'RecordController::create/$1'); + }); + $routes->group('record', function ($routes) { + $routes->get('/', 'RecordController::index'); + $routes->post('create/(:uuid)', 'RecordController::create/$1'); + }); }); }); + diff --git a/app/Controllers/Admin/AdminController.php b/app/Controllers/Admin/AdminController.php new file mode 100644 index 0000000..5961cea --- /dev/null +++ b/app/Controllers/Admin/AdminController.php @@ -0,0 +1,21 @@ +class_path = "Admin/"; + $this->layout = "admin"; + $this->session = $this->session_AuthTrait(); + } +} diff --git a/app/Controllers/Cloudflare/AccountController.php b/app/Controllers/Admin/Cloudflare/AccountController.php similarity index 59% rename from app/Controllers/Cloudflare/AccountController.php rename to app/Controllers/Admin/Cloudflare/AccountController.php index a21a660..ce64453 100644 --- a/app/Controllers/Cloudflare/AccountController.php +++ b/app/Controllers/Admin/Cloudflare/AccountController.php @@ -1,6 +1,6 @@ class_name .= "Account"; - $this->layout = LAYOUTS['admin']; - $this->title = lang("{$this->class_name}.title"); - helper($this->class_name); + $this->class_name = "Account"; + $this->class_path .= $this->class_name; + $this->title = lang("{$this->class_path}.title"); + helper($this->class_path); } final protected function getMyLibrary(): Account { @@ -28,28 +27,13 @@ class AccountController extends CloudflareController } return $this->_myLibrary; } - //Field별 Form Input용 - protected function getFormFieldInput(string $field, string $value, array $inputs = []): array - { - switch ($field) { - case 'type': - $inputs[$field] = form_dropdown( - $field, - $this->getFormFieldInputOption($field, $inputs), - $value - ); - break; - default: - $inputs = parent::getFormFieldInput($field, $value, $inputs); - break; - } - return $inputs; - } protected function create_init(): void { + $this->action = 'create'; $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'authkey', 'type', 'status']; $this->filter_fields = ['type', 'status']; - $this->action = DB_ACTION['CREATE']; + $this->field_rules = $this->getFormFieldRules(); + $this->field_options = $this->getFormFieldOptions(); $this->getMyLibrary()->getMyStorage()->setAction($this->action); } // public function create_form(): RedirectResponse|string @@ -70,19 +54,17 @@ class AccountController extends CloudflareController $this->validateFormDatas(); return parent::create_process(); } - - protected function index_init(): void + public function index(): string { - $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at']; - $this->filter_fields = ['type', 'status']; - $this->action = DB_ACTION['CREATE']; + $this->action = 'index'; + $this->fields = [$this->getMyLibrary()->getMyStorage()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at']; + $this->filter_fields = ['type', 'status']; + $this->batchjob_fields = ['status']; + $this->field_rules = $this->getFormFieldRules(); + $this->field_options = $this->getFormFieldOptions(); $this->getMyLibrary()->getMyStorage()->setAction($this->action); helper(['form']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; - } - public function index(): string - { - $this->index_init(); return parent::list_process(); } } diff --git a/app/Controllers/Cloudflare/CloudflareController.php b/app/Controllers/Admin/Cloudflare/CloudflareController.php similarity index 76% rename from app/Controllers/Cloudflare/CloudflareController.php rename to app/Controllers/Admin/Cloudflare/CloudflareController.php index f58fe9f..7bfd611 100644 --- a/app/Controllers/Cloudflare/CloudflareController.php +++ b/app/Controllers/Admin/Cloudflare/CloudflareController.php @@ -1,28 +1,25 @@ class_name = "Cloudflare/"; - $this->layout = LAYOUTS['admin']; - $this->session = $this->session_AuthTrait(); + $this->class_path .= "Cloudflare/"; } final protected function getAccountModel(): AccountModel { diff --git a/app/Controllers/Cloudflare/RecordController.php b/app/Controllers/Admin/Cloudflare/RecordController.php similarity index 80% rename from app/Controllers/Cloudflare/RecordController.php rename to app/Controllers/Admin/Cloudflare/RecordController.php index 67e0d06..d02347b 100644 --- a/app/Controllers/Cloudflare/RecordController.php +++ b/app/Controllers/Admin/Cloudflare/RecordController.php @@ -1,6 +1,6 @@ class_name .= "Record"; - $this->layout = LAYOUTS['admin']; - $this->title = lang("{$this->class_name}.title"); + $this->class_name = "Record"; + $this->class_path .= $this->class_name; + $this->title = lang("{$this->class_path}.title"); helper($this->class_name); } final protected function getMyLibrary(): Record @@ -30,18 +29,18 @@ class RecordController extends CloudflareController } return $this->_myLibrary; } - protected function getFormFieldInputOption(string $field, array $options = []): array + protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { case $this->getMyLibrary()->getMyStorage()::PARENT: - $options = [ - DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택' - ]; $this->getZoneModel()->where('status', DEFAULTS['STATUS']); - $options = $this->getZoneModel()->getFormFieldInputOption($field, $options); + $options[$field] = [ + DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택', + ...$this->getZoneModel()->getFormFieldOption($field, $options), + ]; break; default: - $options = parent::getFormFieldInputOption($field, $options); + $options = parent::getFormFieldOption($field, $options); break; } return $options; @@ -74,15 +73,11 @@ class RecordController extends CloudflareController } protected function create_init(): void { - $this->fields = [ - $this->getMyLibrary()->getMyStorage()::PARENT, - 'type', - 'content', - 'proxied', - 'hosts', - ]; - $this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied']; $this->action = 'create'; + $this->fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'content', 'proxied', 'hosts']; + $this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied']; + $this->field_rules = $this->getFormFieldRules(); + $this->field_options = $this->getFormFieldOptions(); $this->getMyLibrary()->getMyStorage()->setAction($this->action); } // public function create_form(): RedirectResponse|string diff --git a/app/Controllers/Cloudflare/ZoneController.php b/app/Controllers/Admin/Cloudflare/ZoneController.php similarity index 71% rename from app/Controllers/Cloudflare/ZoneController.php rename to app/Controllers/Admin/Cloudflare/ZoneController.php index ca1d6d6..2525cf9 100644 --- a/app/Controllers/Cloudflare/ZoneController.php +++ b/app/Controllers/Admin/Cloudflare/ZoneController.php @@ -1,6 +1,6 @@ class_name .= "Zone"; - $this->layout = LAYOUTS['admin']; - $this->title = lang("{$this->class_name}.title"); + $this->class_name = "Zone"; + $this->class_path .= $this->class_name; + $this->title = lang("{$this->class_path}.title"); helper($this->class_name); } final protected function getMyLibrary(): Zone @@ -29,43 +29,22 @@ class ZoneController extends CloudflareController } return $this->_myLibrary; } - protected function getFormFieldInputOption(string $field, array $options = []): array + protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { case $this->getMyLibrary()->getMyStorage()::PARENT: - $options = [ - DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택' - ]; $this->getAccountModel()->where('status', DEFAULTS['STATUS']); - $options = $this->getAccountModel()->getFormFieldInputOption($field, $options); - break; - case 'type': - case 'proxied': - $options = [ - DEFAULTS['EMPTY'] => lang("Cloudflare/Record.label." . $field) . ' 선택', - ...lang("Cloudflare/Record.label." . strtoupper($field)), + $options[$field] = [ + DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택', + ...$this->getAccountModel()->getFormFieldOption($field, $options), ]; break; default: - $options = parent::getFormFieldInputOption($field, $options); + $options = parent::getFormFieldOption($field, $options); break; } return $options; } - protected function getFormFieldRule(string $field, array $rules): array - { - if (is_array($field)) { - throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); - } - switch ($field) { - default: - $rules[$field] = $this->getMyLibrary()->getMyStorage()->getFieldRule($field, $rules); - ; - break; - } - return $rules; - } - //전송된 데이터 protected function getFormData(string $field): void { switch ($field) { @@ -100,16 +79,11 @@ class ZoneController extends CloudflareController } protected function create_init(): void { - $this->fields = [ - $this->getMyLibrary()->getMyStorage()::PARENT, - 'domains', - 'hosts', - 'type', - 'content', - 'proxied', - ]; - $this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied']; $this->action = 'create'; + $this->fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'domains', 'hosts', 'type', 'content', 'proxied']; + $this->filter_fields = [$this->getMyLibrary()->getMyStorage()::PARENT, 'type', 'proxied']; + $this->field_rules = $this->getFormFieldRules(); + $this->field_options = $this->getFormFieldOptions(); $this->getMyLibrary()->getMyStorage()->setAction($this->action); } // public function create_form(): RedirectResponse|string diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 2730189..d4cc336 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -9,24 +9,24 @@ use Psr\Log\LoggerInterface; abstract class CommonController extends BaseController { - private $_attributes = []; + private $_viewDatas = []; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); } final public function __get($name) { - if (!array_key_exists($name, $this->_attributes)) { + if (!array_key_exists($name, $this->_viewDatas)) { return null; } - return $this->_attributes[$name]; + return $this->_viewDatas[$name]; } final public function __set($name, $value): void { - $this->_attributes[$name] = $value; + $this->_viewDatas[$name] = $value; } - final public function getAttributes(): array + final public function getViewDatas(): array { - return $this->_attributes; + return $this->_viewDatas; } } diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index e7a3e33..54d37ac 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -17,69 +17,40 @@ abstract class MVController extends CommonController abstract protected function getMyLibrary(): mixed; abstract protected function create_process_submit(): void; abstract protected function modify_process_submit(): void; - //Field별 Form Input Option용 - protected function getFormFieldInputOption(string $field, array $options): array + //Field별 Form Option용 + protected function getFormFieldOption(string $field, array $options): array { switch ($field) { default: - $options = [ - "" => lang($this->class_name . '.label.' . $field) . ' 선택', - ...lang($this->class_name . '.' . strtoupper($field)), + $options[$field] = [ + "" => lang($this->class_path . '.label.' . $field) . ' 선택', + ...lang($this->class_path . '.' . strtoupper($field)), ]; break; } // dd($options); return $options; } - //Field별 Form Input용 - protected function getFormFieldInput(string $field, string $value, array $inputs): array + final protected function getFormFieldOptions(array $options = []): array { - switch ($field) { - case 'status': - $inputs[$field] = form_dropdown( - $field, - $this->getFormFieldInputOption($field, $inputs), - $value - ); - break; - case 'updated_at': - case 'created_at': - $inputs[$field] = form_input($field, $value, ["class" => " calender"]); - break; - default: - $inputs[$field] = form_input($field, $value); - break; - } - return $inputs; - } - final protected function getFormFieldInputs(array $inputs = []): array - { - foreach ($this->fields as $field) { + foreach ($this->filter_fields as $field) { if (is_array($field)) { throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true)); } - $inputs = $this->getFormFieldInput($field, old($field) ?: DEFAULTS['EMPTY'], $inputs); + $options = $this->getFormFieldOption($field, $options); } - return $inputs; - } - //전송된 데이터 Rule - protected function getFormFieldRule(string $field, array $rules): array - { - if (is_array($field)) { - throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); - } - switch ($field) { - default: - $rules[$field] = $this->getMyLibrary()->getMyStorage()->getFieldRule($field, $rules); - break; - } - return $rules; + return $options; } final protected function getFormFieldRules(array $rules = []): array { foreach ($this->fields as $field) { - $rules = $this->getFormFieldRule($field, $rules); + if (is_array($field)) { + throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true)); + } + $rules = $this->getMyLibrary()->getMyStorage()->getFieldRule($field, $rules); } + // var_dump($rules); + // exit; return $rules; } //전송된 데이터 @@ -140,12 +111,11 @@ abstract class MVController extends CommonController { helper(['form']); try { - $this->forminputs = $this->getFormFieldInputs(); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; return view( - strtolower($this->class_name) . "/create", - ['viewDatas' => $this->getAttributes()] + strtolower($this->class_path) . "/create", + data: ['viewDatas' => $this->getViewDatas()] ); } catch (\Exception $e) { log_message("error", $e->getMessage()); @@ -173,12 +143,11 @@ abstract class MVController extends CommonController { helper(['form']); try { - $this->forminputs = $this->getFormFieldInputs(); $this->session->keepFlashdata(SESSION_NAMES['RETURN_URL']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; return view( - strtolower($this->class_name) . "/modify", - ['viewDatas' => $this->getAttributes()] + strtolower($this->class_path) . "/modify", + ['viewDatas' => $this->getViewDatas()] ); } catch (\Exception $e) { log_message("error", $e->getMessage()); @@ -244,7 +213,7 @@ abstract class MVController extends CommonController { //Page, Per_page필요부분 $this->page = (int)$this->request->getVar('page') ?: 1; - $this->per_page = (int)$this->request->getVar('per_page') ?: intval(getenv("default.list.per_page")); + $this->per_page = (int)$this->request->getVar('per_page') ?: intval(getenv("mvc.default.list.per_page")); //줄수 처리용 $page_options = array("" => "줄수선택"); for ($i = $this->per_page; $i <= $this->total_count; $i += $this->per_page) { @@ -281,31 +250,11 @@ abstract class MVController extends CommonController // dd($this->getMyLibrary()->getMyStorage()->getLastQuery()); return $entitys; } - protected function list_field_columns(): array - { - $columns = []; - foreach ($this->fields as $field) { - $label = lang("{$this->class_name}.label.{$field}"); - if ($field == $this->order_field) { - $label .= $this->order_value == 'ASC' ? ICONS["UP"] : ICONS["DOWN"]; - $this->order_value = $this->order_value == 'DESC' ? "ASC" : "DESC"; - } else { - $this->order_value = "ASC"; - } - $columns[] = anchor(current_url() . "?order_field={$field}&order_value={$this->order_value}", $label); - } - return $columns; - } public function list_process(): string { try { //URL처리 $this->uri = $this->request->getUri(); - //입력폼처리 - $this->list_forminputs = $this->getFormFieldInputs(); - //List Field Column처리 - $this->list_field_columns = $this->list_field_columns(); - //total 처리 $this->total_count = $this->list_total(); //pagenation 처리 @@ -315,8 +264,8 @@ abstract class MVController extends CommonController //setting return_url to session flashdata $this->session->setFlashdata(SESSION_NAMES['RETURN_URL'], current_url() . '?' . $this->request->getUri()->getQuery() ?: ""); return view( - strtolower($this->class_name) . "/index", - ['viewDatas' => $this->getAttributes()] + strtolower($this->class_path) . "/index", + ['viewDatas' => $this->getViewDatas()] ); } catch (\Exception $e) { log_message("error", $e->getMessage()); diff --git a/app/Entities/Cloudflare/AccountEntity.php b/app/Entities/Cloudflare/AccountEntity.php index 3281565..b587ce8 100644 --- a/app/Entities/Cloudflare/AccountEntity.php +++ b/app/Entities/Cloudflare/AccountEntity.php @@ -11,7 +11,7 @@ class AccountEntity extends CommonEntity { return "{$this->getPK()}|{$this->getTitle()}|{$this->getAuthKey()}|{$this->attributes['type']}|{$this->attributes['status']}"; } - public function getPK(): int + public function getPK(): string { return $this->attributes[AccountModel::PK]; } diff --git a/app/Entities/Cloudflare/RecordEntity.php b/app/Entities/Cloudflare/RecordEntity.php index 45fd9d5..67149bb 100644 --- a/app/Entities/Cloudflare/RecordEntity.php +++ b/app/Entities/Cloudflare/RecordEntity.php @@ -2,7 +2,7 @@ namespace App\Entities\Cloudflare; -use App\Models\Cloudflare\API\RecordModel; +use App\Models\Cloudflare\RecordModel; use App\Entities\CommonEntity; class RecordEntity extends CommonEntity @@ -11,7 +11,7 @@ class RecordEntity extends CommonEntity { return "{$this->getPK()}|{$this->getParent()}|{$this->getTitle()}|{$this->attributes['host']}|{$this->attributes['content']}|{$this->attributes['proxied']}|{$this->attributes['fixed']}|{$this->attributes['locked']}"; } - public function getPK(): int + public function getPK(): string { return $this->attributes[RecordModel::PK]; } diff --git a/app/Entities/Cloudflare/ZoneEntity.php b/app/Entities/Cloudflare/ZoneEntity.php index 5eb6802..38d7cfe 100644 --- a/app/Entities/Cloudflare/ZoneEntity.php +++ b/app/Entities/Cloudflare/ZoneEntity.php @@ -11,7 +11,7 @@ class ZoneEntity extends CommonEntity { return "{$this->getPK()}|{$this->getParent()}|{$this->getTitle()}|{$this->attributes['development_mode']}|{$this->attributes['ipv6']}|{$this->attributes['security_level']}"; } - public function getPK(): int + public function getPK(): string { return $this->attributes[ZoneModel::PK]; } diff --git a/app/Helpers/Admin/Cloudflare/Account_helper.php b/app/Helpers/Admin/Cloudflare/Account_helper.php new file mode 100644 index 0000000..55d9285 --- /dev/null +++ b/app/Helpers/Admin/Cloudflare/Account_helper.php @@ -0,0 +1,137 @@ +%s", + implode(" ", $attributes), + lang("{$viewDatas['class_path']}.label.{$field}") + ); + break; + } + return $label; +} +//header.php에서 getFieldForm_Helper사용 +function getFieldForm_AccountHelper(string $field, mixed $value, array $viewDatas, array $attributes = []): string +{ + $value = $value ?: DEFAULTS['EMPTY']; + switch ($field) { + case 'user_uid': + $form = form_dropdown($field, $viewDatas['field_options'][$field], $value, [...$attributes, 'class' => "select-field"]); + // // return form_multiselect($field, $field_options[$field], is_array($value) ? [...$value] : [$value], [...$attributes]); + // foreach ($viewDatas['field_options'][$field] as $key => $label) { + // $checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode(DEFAULTS["DELIMITER_ROLE"], $value))) . $label; + // } + // return implode(" ", $checkboxs); + break; + case 'content': + case 'head': + case 'tail': + $form = form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '20', 'cols' => '100']); + break; + case "type": + case "status": + $form = form_dropdown($field, $viewDatas['field_options'][$field], $value, $attributes); + break; + case 'id': + $form = form_input($field, $value, ["placeholder" => "예)sample@test.com", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]); + case 'name': + $form = form_input($field, $value, ["placeholder" => "예)", "style" => "width:60%; ::placeholder{color:silver; opacity: 1;}"]); + break; + case 'updated_at': + case 'created_at': + $form = form_input($field, $value, ['class' => 'calender']); + break; + default: + $form = form_input($field, $value); + break; + } + return $form; +} // + +function getFieldView_AccountHelper(string $field, mixed $entity, array $viewDatas, array $attributes = []) +{ + $value = $entity->$field ?: DEFAULTS['EMPTY']; + switch ($field) { + case 'category_uid': + foreach (array_values($viewDatas['field_options'][$field]) as $category_2depths) { + foreach ($category_2depths as $key => $depth) { + if ($key == $depth) { + $value = $depth; + } + } + } + break; + case 'cost': + case 'price': + case 'sale': + $value = number_format(!$value ? 0 : $value) . "원"; + break; + case 'stock': + case 'view_cnt': + $value = number_format(!$value ? 0 : $value); + break; + case 'content': + $value = html_entity_decode($value); + break; + case 'updated_at': + case 'created_at': + $value = $value ? date("Y-m-d", strtotime($value)) : ""; + break; + default: + if (in_array($field, $viewDatas['filter_fields']) && $value) { + $value = $viewDatas['field_options'][$field][$value]; + } + break; + } + return $value; +} // + +function getListHeaders_AccountHelper(string $field, array $viewDatas, array $attributes = []): string +{ + $label = getFieldLabel_AccountHelper($field, $viewDatas, $attributes); + if ($field == $viewDatas['order_field']) { + $label .= $viewDatas['order_value'] == 'ASC' ? ICONS["UP"] : ICONS["DOWN"]; + } + $order_value = $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC"; + $viewDatas['uri']->addQuery('order_field', $field); + $viewDatas['uri']->addQuery('order_value', $order_value); + $header = anchor((string)$viewDatas['uri'], $label); + switch ($field) { + case 'title': + $attributes = [...$attributes, "class=\"col-2\""]; + break; + } + return sprintf("%s", implode(" ", $attributes), $header); +} +function getListColumns_AccountHelper(string $field, mixed $entity, array $viewDatas, array $attributes = []): string +{ + switch ($field) { + case 'title': + case 'name': + $value = anchor( + current_url() . '/view/' . $entity->getPK(), + getFieldView_AccountHelper($field, $entity, $viewDatas), + ["target" => "_self"] + ); + break; + default: + if (in_array($field, $viewDatas['filter_fields'])) { + $attributes["onChange"] = sprintf( + 'location.href="%s/toggle/%s/%s?%s="+this.options[this.selectedIndex].value', + current_url(), + $entity->getPK(), + $field, + $field + ); + $value = getFieldForm_AccountHelper($field, $entity, $viewDatas, $attributes); + } + $value = getFieldView_AccountHelper($field, $entity, $viewDatas); + break; + } + return $value; +} diff --git a/app/Helpers/Admin/Cloudflare/Zone_helper.php b/app/Helpers/Admin/Cloudflare/Zone_helper.php new file mode 100644 index 0000000..b5e495b --- /dev/null +++ b/app/Helpers/Admin/Cloudflare/Zone_helper.php @@ -0,0 +1,67 @@ +%s", implode(" ", $attributes), lang("{$viewDatas['className']}.label.{$field}")); + break; + } + return $label; +} +//header.php에서 getFieldForm_Helper사용 +function getFieldForm_ZoneHelper($field, $value, array $viewDatas, array $attributes = []) +{ + $value = $value ?: DEFAULTS['EMPTY']; + switch ($field) { + case 'category_uid': + case 'user_uid': + $viewDatas['fieldFormOptions'][$field] = [DEFAULTS['EMPTY'] => lang("{$viewDatas['className']}.label.{$field}") . " 선택", ...$viewDatas['fieldFormOptions'][$field]]; + return form_dropdown($field, $viewDatas['fieldFormOptions'][$field], $value, [...$attributes, 'class' => "select-field"]); + // // return form_multiselect($field, $fieldFormOptions[$field], is_array($value) ? [...$value] : [$value], [...$attributes]); + // foreach ($viewDatas['fieldFormOptions'][$field] as $key => $label) { + // $checkboxs[] = form_checkbox("{$field}[]", $key, in_array($key, explode(DEFAULTS["DELIMITER_ROLE"], $value))) . $label; + // } + // return implode(" ", $checkboxs); + break; + case 'title': + case 'name': + return form_input($field, $value, ["placeholder" => "예)", "style" => "width:60%; ::placeholder{ color:silver; opacity: 1; }"]); + break; + case 'content': + case 'head': + case 'tail': + return form_textarea($field, html_entity_decode($value), ['class' => 'editor', 'rows' => '20', 'cols' => '100']); + break; + case "status": + case "category": + $viewDatas['fieldFormOptions'][$field] = [DEFAULTS['EMPTY'] => lang("{$viewDatas['className']}.label.{$field}") . " 선택", ...$viewDatas['fieldFormOptions'][$field]]; + return form_dropdown($field, $viewDatas['fieldFormOptions'][$field], $value, $attributes); + break; + case 'updated_at': + case 'created_at': + return form_input($field, $value, ['class' => 'calender']); + break; + default: + return form_input($field, $value); + break; + } +} // + +protected function list_field_columns(): array +{ + $columns = []; + foreach ($this->fields as $field) { + $label = lang("{$this->class_path}.label.{$field}"); + if ($field == $this->order_field) { + $label .= $this->order_value == 'ASC' ? ICONS["UP"] : ICONS["DOWN"]; + $this->order_value = $this->order_value == 'DESC' ? "ASC" : "DESC"; + } else { + $this->order_value = "ASC"; + } + $columns[] = anchor(current_url() . "?order_field={$field}&order_value={$this->order_value}", $label); + } + return $columns; +} \ No newline at end of file diff --git a/app/Helpers/Cloudflare/Account_helper.php b/app/Helpers/Cloudflare/Account_helper.php deleted file mode 100644 index b3d9bbc..0000000 --- a/app/Helpers/Cloudflare/Account_helper.php +++ /dev/null @@ -1 +0,0 @@ - "인증Key", 'oldkey' => "이전인증Key", 'title' => "인증명", - 'type' => "가입방식", + 'type' => "인증방식", 'status' => "상태", 'updated_at' => "수정일", 'created_at' => "작성일", diff --git a/app/Language/en/Cloudflare/Record.php b/app/Language/en/Admin/Cloudflare/Record.php similarity index 100% rename from app/Language/en/Cloudflare/Record.php rename to app/Language/en/Admin/Cloudflare/Record.php diff --git a/app/Language/en/Cloudflare/Zone.php b/app/Language/en/Admin/Cloudflare/Zone.php similarity index 100% rename from app/Language/en/Cloudflare/Zone.php rename to app/Language/en/Admin/Cloudflare/Zone.php diff --git a/app/Libraries/CommonLibrary.php b/app/Libraries/CommonLibrary.php index 7c3c9f2..cbc96c9 100644 --- a/app/Libraries/CommonLibrary.php +++ b/app/Libraries/CommonLibrary.php @@ -4,18 +4,20 @@ namespace App\Libraries; abstract class CommonLibrary { - private $_attributes = []; - protected function __construct() {} + private $_libraryDatas = []; + protected function __construct() + { + } final public function __get($name) { - if (!array_key_exists($name, $this->_attributes)) { + if (!array_key_exists($name, $this->_libraryDatas)) { return null; } - return $this->_attributes[$name]; + return $this->_libraryDatas[$name]; } final public function __set($name, $value): void { - $this->_attributes[$name] = $value; + $this->_libraryDatas[$name] = $value; } } diff --git a/app/Models/Cloudflare/AccountModel.php b/app/Models/Cloudflare/AccountModel.php index c9693a3..0f6a84b 100644 --- a/app/Models/Cloudflare/AccountModel.php +++ b/app/Models/Cloudflare/AccountModel.php @@ -34,10 +34,11 @@ class AccountModel extends CommonModel $rules[$field] = "required|valid_emailvalid_email|is_unique[cloudflareauth.id]"; break; case "authkey": - $rules[$field] = $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";; + $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; + ; break; case "oldkey": - $rules[$field] = $rules[$field] = "if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; + $rules[$field] = "if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; break; case "type": $rules[$field] = "if_exist|in_list[standard,enterprise]"; @@ -48,12 +49,12 @@ class AccountModel extends CommonModel } return $rules; } - public function getFormFieldInputOption(string $field, array $options = []): array + public function getFormFieldOption(string $field, array $options = []): array { switch ($field) { default: $this->orderBy(self::TITLE, 'asc'); - $options = parent::getFormFieldInputOption($field, $options); + $options = parent::getFormFieldOption($field, $options); break; } return $options; diff --git a/app/Models/Cloudflare/ZoneModel.php b/app/Models/Cloudflare/ZoneModel.php index 40386f5..b6f2e21 100644 --- a/app/Models/Cloudflare/ZoneModel.php +++ b/app/Models/Cloudflare/ZoneModel.php @@ -30,7 +30,8 @@ class ZoneModel extends CommonModel { switch ($field) { case self::PARENT: - $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";; + $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; + ; break; case self::TITLE: case "plan": @@ -50,15 +51,12 @@ class ZoneModel extends CommonModel } return $rules; } - public function getFormFieldInputOption(string $field, array $options = []): array + public function getFormFieldOption(string $field, array $options = []): array { switch ($field) { - case "status": - $options[$field] = lang($this->class_name . '.' . strtoupper($field)); - break; default: $this->orderBy(self::TITLE, 'asc'); - $options = parent::getFormFieldInputOption($field, $options); + $options = parent::getFormFieldOption($field, $options); break; } return $options; diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 6e30f47..f6f8ca1 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -45,7 +45,7 @@ abstract class CommonModel extends Model protected $beforeDelete = []; protected $afterDelete = []; - private $_action = DB_ACTION["CREATE"]; + private $_action = 'create'; protected function __construct() { parent::__construct(); @@ -89,7 +89,7 @@ abstract class CommonModel extends Model //수동입력인경우 if (!$this->useAutoIncrement) { $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; - $rules[$field] .= $this->getAction() == DB_ACTION["CREATE"] ? "|is_unique[{$this->table}.{$field}]" : ""; + $rules[$field] .= $this->getAction() == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; } else { $rules[$field] = "required|numeric"; } @@ -99,10 +99,10 @@ abstract class CommonModel extends Model $rules[$field] = "required|string"; break; case "passwd": - $rules[$field] = $this->getAction() == DB_ACTION["CREATE"] ? "required" : "if_exist" . "|trim|string"; + $rules[$field] = $this->getAction() == "create" ? "required" : "if_exist" . "|trim|string"; break; case "confirmpassword": - $rules["confirmpassword"] = $this->getAction() == DB_ACTION["CREATE"] ? "required" : "if_exist" . "|trim|string|matches[passwd]"; + $rules["confirmpassword"] = $this->getAction() == "create" ? "required" : "if_exist" . "|trim|string|matches[passwd]"; break; case "email": $rules[$field] = "if_exist|trim|valid_email"; @@ -127,11 +127,14 @@ abstract class CommonModel extends Model final public function getFieldRules(array $fields, array $rules = []): array { foreach ($fields as $field) { + if (is_array($field)) { + throw new \Exception(__FUNCTION__ . "에서 field array 입니다.\n" . var_export($field, true)); + } $rules = $this->getFieldRule($field, $rules); } return $rules; } - public function getFormFieldInputOption(string $field, array $options = []): array + public function getFormFieldOption(string $field, array $options = []): array { switch ($field) { default: @@ -204,7 +207,7 @@ abstract class CommonModel extends Model final protected function create_process($entity, array $formDatas): mixed { //Field에 맞는 Validation Rule 재정의 - $this->setAction(DB_ACTION['CREATE']); + $this->setAction('create'); $this->setValidationRules($this->getFieldRules($this->allowedFields)); //저장하기 전에 데이터 값 변경이 필요한 Field foreach (array_keys($formDatas) as $field) { @@ -222,7 +225,7 @@ abstract class CommonModel extends Model final protected function modify_process($entity, array $formDatas): mixed { //Field에 맞는 Validation Rule 재정의 - $this->setAction(DB_ACTION['MODIFY']); + $this->setAction('modify'); $this->setValidationRules($this->getFieldRules($this->allowedFields)); //저장하기 전에 데이터 값 변경이 필요한 Field foreach (array_keys($formDatas) as $field) { diff --git a/app/Views/cloudflare/account/create.php b/app/Views/admin/cloudflare/account/create.php similarity index 81% rename from app/Views/cloudflare/account/create.php rename to app/Views/admin/cloudflare/account/create.php index 79e4ea5..113abe0 100644 --- a/app/Views/cloudflare/account/create.php +++ b/app/Views/admin/cloudflare/account/create.php @@ -5,9 +5,9 @@ - + diff --git a/app/Views/admin/cloudflare/account/index.php b/app/Views/admin/cloudflare/account/index.php new file mode 100644 index 0000000..6e47e8c --- /dev/null +++ b/app/Views/admin/cloudflare/account/index.php @@ -0,0 +1,68 @@ +extend("layouts/{$viewDatas['layout']}") ?> +section('content') ?> + + "get")) ?> + + + +
- +
+ + + + + + + + + + + + + status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)"> + + + + + + + + + +
번호작업
+ "checkbox_uid_{$entity->getPK()}", "name" => "batchjob_uids[]", "value" => $entity->getPK(), "class" => "batchjobuids_checkboxs"]); ?> + getPK(), $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt), ["target" => "_self"]) ?> + + getPK(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> +
+
+ + +
+ +endSection() ?> \ No newline at end of file diff --git a/app/Views/cloudflare/account/update.php b/app/Views/admin/cloudflare/account/update.php similarity index 100% rename from app/Views/cloudflare/account/update.php rename to app/Views/admin/cloudflare/account/update.php diff --git a/app/Views/cloudflare/account/view.php b/app/Views/admin/cloudflare/account/view.php similarity index 100% rename from app/Views/cloudflare/account/view.php rename to app/Views/admin/cloudflare/account/view.php diff --git a/app/Views/cloudflare/account/index.php b/app/Views/cloudflare/account/index.php deleted file mode 100644 index 527a589..0000000 --- a/app/Views/cloudflare/account/index.php +++ /dev/null @@ -1,56 +0,0 @@ -extend('layouts/admin') ?> -section('content') ?> - -
- "get")) ?> - - include('templates/admin/index_head') ?> - -
- - - - - - - - - - - - - - - - status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)"> - - - - - - - - - -
#@
- "checkbox_uid_{$entity->getPrimaryKey()}", "name" => "batchjob_uids[]", "value" => $entity->getPrimaryKey(), "class" => "batchjobuids_checkboxs"]); ?> - getPrimaryKey(), $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt), ["target" => "_self"]) ?> - - getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> -
-
- - -
- -endSection() ?> \ No newline at end of file diff --git a/app/Views/layouts/admin.php b/app/Views/layouts/admin.php index dad75ba..5145c84 100644 --- a/app/Views/layouts/admin.php +++ b/app/Views/layouts/admin.php @@ -6,10 +6,10 @@ <?= $viewDatas['title'] ?> - + - + @@ -24,20 +24,16 @@
-
- include($viewDatas['layout']['path'] . '/head'); ?> -
+ include(LAYOUTS[$viewDatas['layout']]['path'] . '/head'); ?>
-
include($viewDatas['layout']['path'] . '/left_menu'); ?>
+
include(LAYOUTS[$viewDatas['layout']]['path'] . '/left_menu'); ?>
include('templates/admin/header'); ?>
renderSection('content') ?>
-
- include($viewDatas['layout']['path'] . '/tail'); ?> -
+ include(LAYOUTS[$viewDatas['layout']]['path'] . '/tail'); ?>
diff --git a/app/Views/layouts/admin/head.php b/app/Views/layouts/admin/head.php index a2146e0..67952d0 100644 --- a/app/Views/layouts/admin/head.php +++ b/app/Views/layouts/admin/head.php @@ -1,19 +1,41 @@ -