diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..8f2b3f192 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,11 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug, P3 +assignees: oyeaussie +type: Bug + +--- + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..1dc5cfd42 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,11 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement, P3 +assignees: oyeaussie +type: Feature + +--- + + diff --git a/.gitignore b/.gitignore index b2157d7b9..72a620f63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ public/1/* public/2/* public/* +!public/ping.ico !public/core/ private/* *.sublime-project diff --git a/README.md b/README.md index ae13706b1..3beca538c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # SP Framework - Core Caution!!! - Do not use in production. A man from downunder is still working on it... + + \ No newline at end of file diff --git a/apps/Core/Components/Apps/AppsComponent.php b/apps/Core/Components/Apps/AppsComponent.php index dd728c7d8..c427248ad 100644 --- a/apps/Core/Components/Apps/AppsComponent.php +++ b/apps/Core/Components/Apps/AppsComponent.php @@ -26,20 +26,34 @@ public function viewAction() return $this->throwIdNotFound(); } - if (!isset($app['default_component']) || - isset($app['default_component']) && $app['default_component'] == '0' + $dashboard = $this->modules->components->getComponentByNameForAppType('dashboards', $app['app_type']); + $home = $this->modules->components->getComponentByNameForAppType('home', $app['app_type']); + $errors = $this->modules->components->getComponentByNameForAppType('errors', $app['app_type']); + + if (!isset($app['default_component_guests']) || + isset($app['default_component_guests']) && $app['default_component_guests'] == '0' ) { if ($app['app_type'] === 'core' || $app['app_type'] === 'dash') { - $dashboard = $this->modules->components->getComponentByNameForAppType('dashboards', $app['app_type']); - if ($dashboard) { - $app['default_component'] = $dashboard['id']; + $app['default_component_guests'] = $dashboard['id']; } } else { - $home = $this->modules->components->getComponentByNameForAppType('home', $app['app_type']); + if ($home) { + $app['default_component_guests'] = $home['id']; + } + } + } + if (!isset($app['default_component_users']) || + isset($app['default_component_users']) && $app['default_component_users'] == '0' + ) { + if ($app['app_type'] === 'core' || $app['app_type'] === 'dash') { + if ($dashboard) { + $app['default_component_users'] = $dashboard['id']; + } + } else { if ($home) { - $app['default_component'] = $home['id']; + $app['default_component_users'] = $home['id']; } } } @@ -47,13 +61,9 @@ public function viewAction() if (!isset($app['errors_component']) || isset($app['errors_component']) && $app['errors_component'] == '0' ) { - $errors = $this->modules->components->getComponentByNameForAppType('errors', $app['app_type']); - if ($errors) { $app['errors_component'] = $errors['id']; } else { - $home = $this->modules->components->getComponentByNameForAppType('home', $app['app_type']); - if ($home) { $app['errors_component'] = $home['id']; } @@ -121,7 +131,27 @@ public function viewAction() $this->view->menuBaseStructure = $this->view->modulesMenus = []; } + $selectGuestComponents = []; + $selectUserComponents = []; + $this->view->dashboardComponentId = 0; + $this->view->pageComponentId = 0; foreach ($componentsArr as $key => &$componentValue) { + if ($app['app_type'] === 'core' || $app['app_type'] === 'dash') { + if ($componentValue['route'] !== 'home') { + $selectUserComponents[$key] = $componentValue; + } + $selectGuestComponents[$key] = $componentValue; + } else { + $selectUserComponents[$key] = $componentValue; + $selectGuestComponents[$key] = $componentValue; + } + + if ($componentValue['route'] === 'dashboards') { + $this->view->dashboardComponentId = $componentValue['id']; + } + if ($componentValue['route'] === 'pages') { + $this->view->pageComponentId = $componentValue['id']; + } if ($componentValue['apps']) { if (is_string($componentValue['apps'])) { $componentValue['apps'] = $this->helper->decode($componentValue['apps'], true); @@ -132,10 +162,10 @@ public function viewAction() } } - if (isset($dashboard) && $dashboard) { - if ($dashboard['id'] == $componentValue['id']) { - $componentValue['apps'][$app['id']]['enabled'] = true; - } + if ($dashboard && + $dashboard['id'] == $componentValue['id'] + ) { + $componentValue['apps'][$app['id']]['enabled'] = true; } if ($componentValue['settings']) { @@ -164,7 +194,7 @@ public function viewAction() } } - $components[$key] = $componentValue; + $components[$componentValue['id']] = $componentValue; } //Middlewares @@ -245,7 +275,9 @@ public function viewAction() } } - $this->view->components = msort($components, 'name'); + $this->view->components = msort(array: $components, key: 'name', preserveKey: true); + $this->view->selectUserComponents = $selectUserComponents; + $this->view->selectGuestComponents = $selectGuestComponents; $this->view->middlewares = msort($middlewares, 'sequence'); $this->view->views = msort($views, 'name'); $this->view->mandatoryComponents = $mandatoryComponents; @@ -266,6 +298,7 @@ public function viewAction() $this->view->acceptableUsernames = $this->apps->getAcceptableUsernamesForAppId(); $this->view->dashboards = $this->basepackages->dashboards->init()->getDashboardsByAppType($app['app_type']); + $this->view->pages = $this->basepackages->pages->init()->pages; } else { $this->view->app = null; $domains = $this->domains->domains; @@ -367,7 +400,9 @@ public function addAction() $this->apps->packagesData->responseData ); - $this->addToNotification('add', 'Added new app ' . $this->postData()['name'], null, $this->apps->packagesData->last); + if ($this->apps->packagesData->responseCode === 0) { + $this->addToNotification('add', 'Added new app ' . $this->postData()['name'], null, $this->apps->packagesData->last); + } } /** @@ -386,7 +421,9 @@ public function updateAction() $this->apps->packagesData->responseCode ); - $this->addToNotification('update', 'Updated app', null, $this->apps->packagesData->last ?? []); + if ($this->apps->packagesData->responseCode === 0) { + $this->addToNotification('update', 'Updated app', null, $this->apps->packagesData->last ?? []); + } } /** @@ -405,7 +442,9 @@ public function removeAction() $this->apps->packagesData->responseCode ); - $this->addToNotification('remove', 'Removed app with ID ' . $this->postData()['id']); + if ($this->apps->packagesData->responseCode === 0) { + $this->addToNotification('remove', 'Removed app with ID ' . $this->postData()['id']); + } } public function getFiltersAction() diff --git a/apps/Core/Components/Auth/AuthComponent.php b/apps/Core/Components/Auth/AuthComponent.php index 6becdbf5e..c3ecf4a02 100644 --- a/apps/Core/Components/Auth/AuthComponent.php +++ b/apps/Core/Components/Auth/AuthComponent.php @@ -88,7 +88,7 @@ public function loginAction() { $this->requestIsPost(); - $auth = $this->access->auth->attempt($this->postData()); + $auth = $this->access->auth->login($this->postData()); $this->addResponse( $this->access->auth->packagesData->responseMessage, diff --git a/apps/Core/Components/Dashboards/DashboardsComponent.php b/apps/Core/Components/Dashboards/DashboardsComponent.php index aa405d32b..24ccc7618 100644 --- a/apps/Core/Components/Dashboards/DashboardsComponent.php +++ b/apps/Core/Components/Dashboards/DashboardsComponent.php @@ -12,16 +12,25 @@ class DashboardsComponent extends BaseComponent public function viewAction() { if (isset($this->getData()['widgets'])) { - $this->getNewToken(); - if ($this->getData()['widgets'] == 'info') { return $this->basepackages->widgets->getWidget($this->getData()['id'], 'info')['info']; } else if ($this->getData()['widgets'] == 'content') {//This is when we add the widget via list of widgets in dashboard. $dashboardWidget = $this->basepackages->dashboards->getDashboardWidgetById($this->getData()['id'], $this->getData()['did']); - $dashboardWidget['getWidgetData'] = true; + if ($dashboardWidget) { + $dashboardWidget['getWidgetData'] = true; + + $dashboardWidgetContent = $this->basepackages->widgets->getWidget($this->getData()['wid'], 'content', $dashboardWidget); - return $this->basepackages->widgets->getWidget($this->getData()['wid'], 'content', $dashboardWidget)['content']; + if (isset($dashboardWidgetContent['content'])) { + return $dashboardWidgetContent['content']; + } + } + + //Remove Widget as it might be stale as the source content would have been deleted. + $this->basepackages->dashboards->removeWidgetFromDashboard(['dashboard_id' => $this->getData()['did'], 'id' => $this->getData()['id']]); + + return false; } } else { if (is_string($this->app['settings'])) { @@ -34,7 +43,7 @@ public function viewAction() if ($this->getData()['id'] != 0) { $dashboardId = $this->getData()['id']; - $dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false); + $dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true); if (isset($this->app['settings']['defaultDashboard'])) { if ($this->app['settings']['defaultDashboard'] == $dashboard['id']) { @@ -134,9 +143,11 @@ public function viewAction() $this->view->dashboards = $dashboards; - $this->view->dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false); + $this->view->dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true); + + $this->view->widgetsTree = $this->basepackages->widgets->getWidgetsTree('dashboards'); - $this->view->widgetsTree = $this->basepackages->widgets->getWidgetsTree(); + $this->getNewToken();//We need this token as we initiate a getDashboardWidgets(); } } } diff --git a/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php b/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php index 6d8fae27b..5a3e13039 100644 --- a/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php +++ b/apps/Core/Components/Devtools/Extractgeodata/ExtractgeodataComponent.php @@ -41,8 +41,9 @@ public function processAction() $success = false; if (isset($this->postData()['geo']) && $this->postData()['geo'] == 'true') { - $success = $this->geoExtractDataPackage->downloadGeoData(); - $success = $this->geoExtractDataPackage->processGeoData(); + $success = $this->geoExtractDataPackage->downloadGeoCountriesData(); + $success = $this->geoExtractDataPackage->downloadGeoPostcodeData(); + $success = $this->geoExtractDataPackage->processGeoCountriesData(); } if (isset($this->postData()['timezone']) && $this->postData()['timezone'] == 'true') { @@ -85,13 +86,18 @@ protected function registerProgressMethods() $methods = array_merge($methods, [ [ - 'method' => 'downloadGeoData', - 'text' => 'Download Geo Location Data...', + 'method' => 'downloadGeoCountriesData', + 'text' => 'Download Geo Location Countries Data...', 'remoteWeb' => true ], [ - 'method' => 'processGeoData', - 'text' => 'Process Geo Location Data...' + 'method' => 'downloadGeoPostcodeData', + 'text' => 'Download Geo Location Postcode Data...', + 'remoteWeb' => true + ], + [ + 'method' => 'processGeoCountriesData', + 'text' => 'Process Geo Location Countries Data...' ] ] ); diff --git a/apps/Core/Components/Devtools/Migrator/MigratorComponent.php b/apps/Core/Components/Devtools/Migrator/MigratorComponent.php index 787778df5..187bf812a 100644 --- a/apps/Core/Components/Devtools/Migrator/MigratorComponent.php +++ b/apps/Core/Components/Devtools/Migrator/MigratorComponent.php @@ -13,7 +13,7 @@ public function initialize() { $this->migratorPackage = $this->usePackage(DevtoolsMigrator::class); - $this->setModuleSettings(true); + $this->setModuleSettings(); $this->setModuleSettingsData([ 'apis' => $this->migratorPackage->getAvailableApis(true, false), diff --git a/apps/Core/Components/Devtools/Modules/ModulesComponent.php b/apps/Core/Components/Devtools/Modules/ModulesComponent.php index de4b51cbe..d00b1ecd7 100644 --- a/apps/Core/Components/Devtools/Modules/ModulesComponent.php +++ b/apps/Core/Components/Devtools/Modules/ModulesComponent.php @@ -18,7 +18,7 @@ public function initialize() { $this->modulesPackage = $this->usePackage(DevtoolsModules::class); - $this->setModuleSettings(true); + $this->setModuleSettings(); $this->setModuleSettingsData([ 'apis' => $this->modulesPackage->getAvailableApis(true, false), @@ -55,26 +55,41 @@ public function viewAction() } } + $this->view->includecoremodules = false; if (isset($this->getData()['includecoremodules'])) { $this->view->includecoremodules = true; } + $this->view->clone = false; if (isset($this->getData()['clone'])) { $this->view->clone = true; } + $this->view->newrelease = false; if (isset($this->getData()['newrelease'])) { $this->view->newrelease = true; } + $this->view->subview = false; if (isset($this->getData()['subview'])) { $this->view->subview = true; } + $this->view->selectedAppType = 0; + if (isset($this->getData()['apptype'])) { + $this->view->selectedAppType = $this->getData()['apptype']; + } + $appTypesArr = $this->apps->types->types; $appTypes = []; foreach ($appTypesArr as $key => $value) { + if (isset($this->getData()['id']) && $this->view->selectedAppType !== 0) { + if ($value['app_type'] !== $this->view->selectedAppType) { + continue; + } + } + $appTypes[$value['app_type']]['id'] = $value['app_type']; $appTypes[$value['app_type']]['name'] = $value['name']; } @@ -105,24 +120,77 @@ public function viewAction() foreach ($modulesTypeArr as $modulesType) { if ($modulesType === 'bundles') { $modulesArr['modules'] = msort($this->modules->{$modulesType}->{$modulesType}, 'name'); + + foreach ($modulesArr['modules'] as $typesModuleKey => $typesModule) { + if (isset($this->getData()['apptype'])) { + if ($typesModule['app_type'] !== $this->getData()['apptype']) { + if (isset($this->getData()['includecoremodules'])) { + if ($typesModule['app_type'] !== 'core' && + $typesModule['app_type'] !== $this->getData()['apptype'] + ) { + unset($modulesArr['modules'][$typesModuleKey]); + } + } else { + if ($typesModule['app_type'] !== $this->getData()['apptype']) { + unset($modulesArr['modules'][$typesModuleKey]); + } + } + } + } + } } else if ($modulesType === 'apptypes') { $modulesArr['modules'] = msort($this->apps->types->types, 'name'); - if (!isset($this->getData()['includecoremodules'])) { - foreach ($modulesArr['modules'] as $typesModuleKey => $typesModule) { + + foreach ($modulesArr['modules'] as $typesModuleKey => $typesModule) { + $modulesArr['modules'][$typesModuleKey]['data']['app_type'] = $typesModule['app_type']; + + if (!isset($this->getData()['includecoremodules'])) { if ($typesModule['app_type'] === 'core') { unset($modulesArr['modules'][$typesModuleKey]); } } + + if (isset($this->getData()['apptype'])) { + if ($typesModule['app_type'] !== $this->getData()['apptype']) { + if (isset($this->getData()['includecoremodules'])) { + if ($typesModule['app_type'] !== 'core' && + $typesModule['app_type'] !== $this->getData()['apptype'] + ) { + unset($modulesArr['modules'][$typesModuleKey]); + } + } else { + if ($typesModule['app_type'] !== $this->getData()['apptype']) { + unset($modulesArr['modules'][$typesModuleKey]); + } + } + } + } } } else { $modulesArr = $this->processModulesArr(msort($this->modules->{$modulesType}->{$modulesType}, 'name')); ${$modulesType . 'CategoryArr'} = $modulesArr['categoryArr']; + + foreach ($modulesArr['modules'] as $typesModuleKey => $typesModule) { + if (isset($this->getData()['apptype'])) { + if (isset($this->getData()['includecoremodules'])) { + if ($typesModule['app_type'] !== 'core' && + $typesModule['app_type'] !== $this->getData()['apptype'] + ) { + unset($modulesArr['modules'][$typesModuleKey]); + } + } else { + if ($typesModule['app_type'] !== $this->getData()['apptype']) { + unset($modulesArr['modules'][$typesModuleKey]); + } + } + } + } } if ($modulesArr['modules'] && count($modulesArr['modules']) > 0) { if ($modulesType === 'views') { - if (isset($this->view->subview)) { - foreach ($modulesArr['modules'] as $moduleArrKey => $moduleArr) { + foreach ($modulesArr['modules'] as $moduleArrKey => $moduleArr) { + if ($this->view->subview) { if (array_key_exists('is_subview', $moduleArr) && $moduleArr['is_subview'] == true ) { @@ -130,10 +198,10 @@ public function viewAction() } $modules[$modulesType]['value'] = ucfirst($modulesType); $modules[$modulesType]['childs'][$moduleArrKey] = $moduleArr; + } else { + $modules[$modulesType]['value'] = ucfirst($modulesType); + $modules[$modulesType]['childs'] = $modulesArr['modules']; } - } else if (!isset($this->view->subview)) { - $modules[$modulesType]['value'] = ucfirst($modulesType); - $modules[$modulesType]['childs'] = $modulesArr['modules']; } } else { $modules[$modulesType]['value'] = ucfirst($modulesType); @@ -176,7 +244,7 @@ public function viewAction() unset($modules['components']); unset($modules['middlewares']); unset($modules['bundles']); - if (!isset($this->view->subview)) { + if (!$this->view->subview) { unset($modules['views']); } } @@ -193,12 +261,14 @@ public function viewAction() foreach ($modulesTypeArr['childs'] as $childKey => &$child) { $child = $this->modulesPackage->validateFilesHash($child); - if ($child['repoExists'] && !$child['isModified'] && $child['latestRelease']) { + if ($child['repoExists'] && !$child['isModified'] && !$child['releasePending'] && $child['latestRelease']) { unset($modules[$moduleType]['childs'][$childKey]); + + continue; } - if (isset($child['modified_files']) && count($child['modified_files']) > 0) { - $modifiedModules[$child['id']] = $child['modified_files']; + if ($child['isModified'] && isset($child['modified_files'])) { + $modifiedModules[$child['module_type']][$child['id']] = $child['modified_files']; } } } @@ -215,39 +285,42 @@ public function viewAction() $this->view->modules = $modules; - $modulesJson = []; + $apis = $this->modulesPackage->getAvailableApis(false, true); - foreach ($modules as $moduleKey => $moduleJson) { - if ($moduleKey === 'bundles' && - !$this->view->bundles - ) { - continue; - } + $this->view->modulesJson = ''; + if (isset($this->getData()['id'])) { + $modulesJson = []; - foreach ($moduleJson['childs'] as $childKey => $child) { - $modulesJson[$moduleKey][$child['id']] = - [ - 'id' => $child['id'], - 'name' => $child['name'], - 'version' => $child['version'] ?? null, - 'repo' => $child['repo'] ?? null, - ]; + foreach ($modules as $moduleKey => $moduleJson) { + if ($moduleKey === 'bundles' && + !$this->view->bundles + ) { + continue; + } - if ($moduleKey === 'views') { + foreach ($moduleJson['childs'] as $childKey => $child) { $modulesJson[$moduleKey][$child['id']] = - array_merge($modulesJson[$moduleKey][$child['id']], - [ - 'base_view_module_id' => $child['base_view_module_id'], - 'is_subview' => $child['is_subview'] ?? false - ] - ); + [ + 'id' => $child['id'], + 'name' => $child['name'], + 'version' => $child['version'] ?? null, + 'repo' => $child['repo'] ?? null, + ]; + + if ($moduleKey === 'views') { + $modulesJson[$moduleKey][$child['id']] = + array_merge($modulesJson[$moduleKey][$child['id']], + [ + 'base_view_module_id' => $child['base_view_module_id'], + 'is_subview' => $child['is_subview'] ?? false + ] + ); + } } } - } - - $this->view->modulesJson = $this->helper->encode($modulesJson); - $apis = $this->modulesPackage->getAvailableApis(false, true); + $this->view->modulesJson = $this->helper->encode($modulesJson); + } if (isset($this->getData()['id']) && isset($this->getData()['module']) && @@ -278,7 +351,8 @@ public function viewAction() $this->view->apis = $apis; $this->view->moduleTypes = $this->modulesPackage->getModuleTypes(); $this->view->moduleSettings = $this->modulesPackage->getDefaultSettings(); - if (isset($this->view->subview)) { + $this->view->moduleFilters = $this->modulesPackage->getDefaultFilters(); + if ($this->view->subview) { $this->view->moduleDependencies = $this->modulesPackage->getDefaultDependencies($type, true); } else { $this->view->moduleDependencies = $this->modulesPackage->getDefaultDependencies($type); @@ -405,6 +479,9 @@ public function viewAction() if (isset($module['settings']) && is_array($module['settings'])) { $this->view->moduleSettings = $module['settings'] = $this->helper->encode($module['settings']); } + if (isset($module['filters']) && is_array($module['filters'])) { + $this->view->moduleFilters = $module['filters'] = $this->helper->encode($module['filters']); + } if (isset($module['dependencies']) && is_array($module['dependencies'])) { $this->view->moduleDependencies = $module['dependencies'] = $this->helper->encode($module['dependencies']); } @@ -427,7 +504,6 @@ public function viewAction() $module['module_type'] = 'apptypes'; $module['id'] = $module['module_details']['id']; - } catch (\throwable $e) { throw new \Exception($e->getMessage()); } @@ -571,6 +647,19 @@ public function updateAction() ); } + public function bulkAction() + { + $this->requestIsPost(); + + $this->modulesPackage->bulkModule($this->postData()); + + $this->addResponse( + $this->modulesPackage->packagesData->responseMessage, + $this->modulesPackage->packagesData->responseCode, + $this->modulesPackage->packagesData->responseData ?? [] + ); + } + public function removeAction() { $this->requestIsPost(); @@ -583,6 +672,18 @@ public function removeAction() ); } + public function toggleVisibilityRepoAction() + { + $this->requestIsPost(); + + $this->modulesPackage->toggleVisibilityRepo($this->postData()); + + $this->addResponse( + $this->modulesPackage->packagesData->responseMessage, + $this->modulesPackage->packagesData->responseCode + ); + } + public function removeRepoAction() { $this->requestIsPost(); @@ -614,6 +715,8 @@ protected function processModulesArr($modulesArr) $modulesArr['categoryArr'] = []; foreach ($modulesArr['modules'] as $key => &$module) { + $modulesArr['modules'][$key]['data']['app_type'] = $module['app_type']; + if (!isset($modulesArr['categoryArr'][$module['category']])) { $modulesArr['categoryArr'][$module['category']]['id'] = $module['category']; $modulesArr['categoryArr'][$module['category']]['name'] = ucfirst($module['category']); @@ -888,4 +991,17 @@ public function getModifiedFilesHashAction() $this->modulesPackage->packagesData->responseCode ); } + + public function getDiffAction() + { + $this->requestIsPost(); + + $this->modulesPackage->getDiff($this->postData()); + + $this->addResponse( + $this->modulesPackage->packagesData->responseMessage, + $this->modulesPackage->packagesData->responseCode, + $this->modulesPackage->packagesData->responseData ?? [], + ); + } } \ No newline at end of file diff --git a/apps/Core/Components/Errors/ErrorsComponent.php b/apps/Core/Components/Errors/ErrorsComponent.php index 9dae5d098..5dddd0d69 100644 --- a/apps/Core/Components/Errors/ErrorsComponent.php +++ b/apps/Core/Components/Errors/ErrorsComponent.php @@ -22,14 +22,28 @@ public function controllerNotFoundAction() public function controllerPackageDependencyErrorAction() { - $this->view->pick('errors/controllerdependencyerror'); + $this->view->pick('common/errors/controllerdependencyerror'); $this->addResponse('Component Dependency Error', 1); } public function controllerViewDependencyErrorAction() { - $this->view->pick('errors/controllerdependencyerror'); + $this->view->pick('common/errors/controllerdependencyerror'); + + $this->addResponse('Component Dependency Error', 1); + } + + public function appPackagePermissionDeniedAction() + { + $this->view->pick('common/errors/controllerdependencyerror'); + + $this->addResponse('Component Dependency Error', 1); + } + + public function appComponentPermissionDeniedAction() + { + $this->view->pick('common/errors/controllerdependencyerror'); $this->addResponse('Component Dependency Error', 1); } @@ -82,4 +96,4 @@ public function invalidDataAction(...$params) $this->addResponse('Invalid data provided. Error: ' . $params[0], 1); } -} \ No newline at end of file +} diff --git a/apps/Core/Components/Home/HomeComponent.php b/apps/Core/Components/Home/HomeComponent.php index c03bd4496..2a9e4a680 100644 --- a/apps/Core/Components/Home/HomeComponent.php +++ b/apps/Core/Components/Home/HomeComponent.php @@ -12,11 +12,19 @@ class HomeComponent extends BaseComponent public function viewAction() { try { - if ($this->app['default_component'] == 0) { - return; - } + if ($this->access->auth->check()) { + if ($this->app['default_component_users'] == 0) { + return; + } - $defaultComponent = $this->modules->components->getById($this->app['default_component']); + $defaultComponent = $this->modules->components->getById($this->app['default_component_users']); + } else { + if ($this->app['default_component_guests'] == 0) { + return; + } + + $defaultComponent = $this->modules->components->getById($this->app['default_component_guests']); + } if ($defaultComponent['class'] === get_class($this)) { return; diff --git a/apps/Core/Components/Modules/ModulesComponent.php b/apps/Core/Components/Modules/ModulesComponent.php index e8e6cc2f0..93a85ff08 100644 --- a/apps/Core/Components/Modules/ModulesComponent.php +++ b/apps/Core/Components/Modules/ModulesComponent.php @@ -10,7 +10,7 @@ public function initialize() { $this->modulesManager = $this->usePackage('manager'); - $this->setModuleSettings(true); + $this->setModuleSettings(); $this->setModuleSettingsData([ 'apis' => $this->modulesManager->getAvailableApis(true, false), diff --git a/apps/Core/Components/Pages/Install/component.json b/apps/Core/Components/Pages/Install/component.json new file mode 100644 index 000000000..0cbbed1dc --- /dev/null +++ b/apps/Core/Components/Pages/Install/component.json @@ -0,0 +1,53 @@ +{ + "name" : "Pages", + "route" : "pages", + "description" : "
Manage pages via this component
", + "module_type" : "components", + "app_type" : "core", + "category" : "admin", + "version" : "0.0.0", + "repo" : "https://.../", + "class" : "Apps\\Core\\Components\\Pages\\PagesComponent", + "dependencies" : + { + "core" : + { + "name" : "Core", + "version" : "0.0.0", + "repo" : "https://.../" + }, + "components" : [], + "packages" : [], + "middlewares" : [], + "views" : [], + "external" : [], + "externals" : [] + }, + "menu" : + { + "pages" : + { + "title" : "pages", + "icon" : "file-code", + "link" : "pages" + }, + "seq" : "0" + }, + "widgets" : + [ + { + "name" : "HTML Code", + "method" : "htmlCode", + "multiple" : true, + "max_multiple" : 20, + "settings" : [] + } + ], + "settings" : + { + "mandatory" : + { + "core" : true + } + } +} \ No newline at end of file diff --git a/apps/Core/Components/Pages/PagesComponent.php b/apps/Core/Components/Pages/PagesComponent.php new file mode 100644 index 000000000..acf6d0b3f --- /dev/null +++ b/apps/Core/Components/Pages/PagesComponent.php @@ -0,0 +1,217 @@ +pages = $this->basepackages->pages; + } + + /** + * @acl(name=view) + */ + public function viewAction() + { + if (isset($this->getData()['id'])) { + $this->view->mode = 'edit'; + + $this->view->contentSources = + [ + 'file' => [ + 'source'=> 'file', + 'name' => 'HTML File' + ], + 'code' => [ + 'source'=> 'code', + 'name' => 'HTML Code' + ], + ]; + + $appTypesArr = $this->apps->types->types; + $appTypes = []; + + foreach ($appTypesArr as $value) { + $appTypes[$value['app_type']]['id'] = $value['app_type']; + $appTypes[$value['app_type']]['name'] = $value['name']; + } + + $this->view->appTypes = $appTypes; + + $appsArr = $this->apps->apps; + $apps = []; + + foreach ($appsArr as $app) { + $apps[$app['id']]['id'] = $app['id']; + $apps[$app['id']]['name'] = $app['name']; + $apps[$app['id']]['route'] = $app['route']; + $apps[$app['id']]['data']['app_type'] = $app['app_type']; + } + + $this->view->apps = $apps; + + if ($this->getData()['id'] != 0) { + $page = $this->pages->getById($this->getData()['id']); + + if (!$page) { + return $this->throwIdNotFound(); + } + + if (!isset($this->getData()['edit'])) { + if (!in_array($this->apps->getAppInfo()['route'], $page['visible_on_apps'])) { + return $this->throwIdNotFound(); + } + if ($this->apps->getAppInfo()['app_type'] !== $page['app_type']) { + return $this->throwIdNotFound(); + } + + $this->getQueryArr['id'] = null;//Add this to disable token generation on page view. + + $this->view->mode = 'view'; + + unset($this->view->contentSources); + unset($this->view->apps); + + if ($page['content_source'] === 'file') { + //Check file existence + try { + $path = str_replace(base_path(), '', $this->view->getViewsDir()); + + if ($this->localContent->fileExists($path . 'pages/files/' . $page['html_file'] . '.html')) { + $page['html_code'] = $this->view->getPartial('pages/files/' . $page['html_file']); + } else { + $this->setErrorDispatcher('templateError'); + + return; + } + } catch (\throwable | FilesystemException | UnableToCheckExistence | UnableToReadFile $e) { + throw $e; + } + } else { + if (strpos($page['html_code'], '')) { + $page['html_code'] = 'JavaScript is not supported in pages. Page will not be processed!'; + + $this->view->setViewsDir($this->modules->views->getPhalconViewPath()); + + $this->view->page = $page; + + return; + } + } + + $page = $this->pages->processWidgets($page); + + $this->view->setViewsDir($this->modules->views->getPhalconViewPath()); + } + + $this->view->page = $page; + } + + $this->view->pick('pages/view'); + + return; + } else { + if ($this->dispatcher->wasForwarded()) { + $pageId = 0; + + if ($this->access->auth->account()) { + if (isset($this->app['settings']['defaultUserPage'])) { + $pageId = (int) $this->app['settings']['defaultUserPage']; + } + } else { + if (isset($this->app['settings']['defaultGuestPage'])) { + $pageId = (int) $this->app['settings']['defaultGuestPage']; + } + } + + $this->getQueryArr['id'] = $pageId; + + return $this->viewAction(); + } + } + + $controlActions = + [ + 'includeQ' => true, + 'actionsToEnable' => + [ + 'view' => 'pages/q/', + 'edit' => 'pages/q/edit/true/', + 'remove' => 'pages/remove/q/' + ] + ]; + + $this->generateDTContent( + $this->pages, + 'pages/view', + null, + ['name', 'app_type', 'visible_on_apps'], + true, + ['name', 'app_type', 'visible_on_apps'], + $controlActions, + [], + null, + 'name' + ); + + $this->view->pick('pages/list'); + } + + /** + * @acl(name=add) + */ + public function addAction() + { + $this->requestIsPost(); + + $this->pages->addPage($this->postData()); + + $this->addResponse( + $this->pages->packagesData->responseMessage, + $this->pages->packagesData->responseCode, + $this->pages->packagesData->responseData + ); + } + + /** + * @acl(name=update) + */ + public function updateAction() + { + $this->requestIsPost(); + + $this->pages->updatePage($this->postData()); + + $this->addResponse( + $this->pages->packagesData->responseMessage, + $this->pages->packagesData->responseCode, + $this->pages->packagesData->responseData + ); + } + + /** + * @acl(name=remove) + */ + public function removeAction() + { + $this->requestIsPost(); + + $this->pages->removePage($this->postData()); + + $this->addResponse( + $this->pages->packagesData->responseMessage, + $this->pages->packagesData->responseCode + ); + } +} \ No newline at end of file diff --git a/apps/Core/Components/Pages/Widgets.php b/apps/Core/Components/Pages/Widgets.php new file mode 100644 index 000000000..97a6b7451 --- /dev/null +++ b/apps/Core/Components/Pages/Widgets.php @@ -0,0 +1,14 @@ +getWidgetContent($widget, $dashboardWidget); + } +} \ No newline at end of file diff --git a/apps/Core/Components/Pages/Widgets/Install/component.json b/apps/Core/Components/Pages/Widgets/Install/component.json new file mode 100644 index 000000000..f81113fd0 --- /dev/null +++ b/apps/Core/Components/Pages/Widgets/Install/component.json @@ -0,0 +1,35 @@ +{ + "name" : "Pages Widgets", + "route" : "pages/widgets", + "description" : "Manage pages widgets via this component
", + "module_type" : "components", + "app_type" : "core", + "category" : "admin", + "version" : "0.0.0", + "repo" : "https://.../", + "class" : "Apps\\Core\\Components\\Pages\\Widgets\\WidgetsComponent", + "dependencies" : + { + "core" : + { + "name" : "Core", + "version" : "0.0.0", + "repo" : "https://.../" + }, + "components" : [], + "packages" : [], + "middlewares" : [], + "views" : [], + "external" : [], + "externals" : [] + }, + "menu" : "false", + "widgets" : [], + "settings" : + { + "mandatory" : + { + "core" : true + } + } +} \ No newline at end of file diff --git a/apps/Core/Components/Pages/Widgets/WidgetsComponent.php b/apps/Core/Components/Pages/Widgets/WidgetsComponent.php new file mode 100644 index 000000000..e883f0029 --- /dev/null +++ b/apps/Core/Components/Pages/Widgets/WidgetsComponent.php @@ -0,0 +1,152 @@ +pageswidgets = $this->basepackages->pageswidgets; + } + + /** + * @acl(name=view) + */ + public function viewAction() + { + //In case of nested components, you need to disable parsing of main layout else view.html in pages directory will also be parsed. + $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT); + + if (isset($this->getData()['widgetinfo']) && + $this->getData()['widgetinfo'] == 'true' + ) { + return $this->basepackages->widgets->getWidget($this->getData()['id'], 'info')['info']; + } + + if (isset($this->getData()['widgetsettings']) && + $this->getData()['widgetsettings'] == 'true' + ) { + return $this->basepackages->widgets->getWidget($this->getData()['id'], 'settings')['settings']; + } + + $this->view->widgetsTree = $this->basepackages->widgets->getWidgetsTree('pages'); + + if (isset($this->getData()['id'])) { + if ($this->getData()['id'] != 0) { + $pagewidget = $this->pageswidgets->getById($this->getData()['id']); + + if (!$pagewidget) { + return $this->throwIdNotFound(); + } + + $pagewidget['info'] = $this->basepackages->widgets->getWidget($pagewidget['widget_id'], 'info')['info']; + $pagewidget['settings'] = $this->basepackages->widgets->getWidget($pagewidget['widget_id'], 'settings', $pagewidget)['settings']; + + $this->view->pagewidget = $pagewidget; + + $viewsPath = base_path('apps/' . + ucfirst($this->component['app_type']) . + '/Views/' . $this->modules->views->getViewInfo()['name'] . + '/html/'); + $this->modules->views->setPhalconViewPath($viewsPath); + + $this->view->setViewsDir($this->modules->views->getPhalconViewPath() . 'pages/'); + } + + $this->view->pick('widgets/view'); + + return; + } + + $controlActions = + [ + 'actionsToEnable' => + [ + 'edit' => 'pages/widgets', + 'remove' => 'pages/widgets/remove/' + ] + ]; + + $replaceColumns = + function ($dataArr) { + if ($dataArr && is_array($dataArr) && count($dataArr) > 0) { + foreach ($dataArr as &$data) { + if (isset($this->view->widgetsTree[$data['widget_id']])) { + $data['widget_id'] = $this->view->widgetsTree[$data['widget_id']]['name']; + } + } + } + + return $dataArr; + }; + + $this->generateDTContent( + $this->pageswidgets, + 'pages/widgets/view', + null, + ['name', 'widget_id'], + true, + ['name', 'widget_id'], + $controlActions, + ['widget_id' => 'widget (app type)'], + $replaceColumns, + 'name' + ); + + $this->view->pick('widgets/list'); + } + + /** + * @acl(name=add) + */ + public function addAction() + { + $this->requestIsPost(); + + $this->pageswidgets->addPagesWidget($this->postData()); + + $this->addResponse( + $this->pageswidgets->packagesData->responseMessage, + $this->pageswidgets->packagesData->responseCode, + $this->pageswidgets->packagesData->responseData + ); + } + + /** + * @acl(name=update) + */ + public function updateAction() + { + $this->requestIsPost(); + + $this->pageswidgets->updatePagesWidget($this->postData()); + + $this->addResponse( + $this->pageswidgets->packagesData->responseMessage, + $this->pageswidgets->packagesData->responseCode, + $this->pageswidgets->packagesData->responseData + ); + } + + /** + * @acl(name=remove) + */ + public function removeAction() + { + $this->requestIsPost(); + + $this->pageswidgets->removePagesWidget($this->postData()); + + $this->addResponse( + $this->pageswidgets->packagesData->responseMessage, + $this->pageswidgets->packagesData->responseCode + ); + } +} \ No newline at end of file diff --git a/apps/Core/Components/Register/RegisterComponent.php b/apps/Core/Components/Register/RegisterComponent.php index 26678dde7..a5a993c3e 100644 --- a/apps/Core/Components/Register/RegisterComponent.php +++ b/apps/Core/Components/Register/RegisterComponent.php @@ -146,6 +146,8 @@ public function viewAction() $this->response->setStatusCode(404); return $this->response->send(); + + exit; } $this->view->setLayout('auth'); @@ -245,4 +247,4 @@ public function apiClientAction() return $this->api->registerClient(); } -} \ No newline at end of file +} diff --git a/apps/Core/Components/System/Core/CoreComponent.php b/apps/Core/Components/System/Core/CoreComponent.php index 5d30d3a9b..6cc8c7ea8 100644 --- a/apps/Core/Components/System/Core/CoreComponent.php +++ b/apps/Core/Components/System/Core/CoreComponent.php @@ -182,6 +182,26 @@ public function viewAction() $this->view->ffStores = $ffStores; + $this->view->countries = $this->basepackages->geoCountries->getAll()->geoCountries; + + $this->view->timezones = $this->basepackages->geoTimezones->getAll()->geoTimezones; + + if (!isset($core['settings']['locale']['country_iso3']) || + (isset($core['settings']['locale']['country_iso3']) && $core['settings']['locale']['country_iso3'] === '') + ) { + if ($this->config->locale->country_iso3) { + $core['settings']['locale']['country_iso3'] = $this->config->locale->country_iso3; + } + } + + if (!isset($core['settings']['locale']['timezone']) || + (isset($core['settings']['locale']['timezone']) && $core['settings']['locale']['timezone'] === '') + ) { + if ($this->config->locale->timezone) { + $core['settings']['locale']['timezone'] = $this->config->locale->timezone; + } + } + $this->view->core = $core; } } diff --git a/apps/Core/Components/System/Email/Queue/QueueComponent.php b/apps/Core/Components/System/Email/Queue/QueueComponent.php index 19eca1ac0..14a483b02 100644 --- a/apps/Core/Components/System/Email/Queue/QueueComponent.php +++ b/apps/Core/Components/System/Email/Queue/QueueComponent.php @@ -31,12 +31,13 @@ public function viewAction() $email = $this->formatStatus(0, $email); $email = $this->formatPriority(0, $email); - $email = $this->formatSentOn(0, $email); + $email = $this->formatSentOn(0, $email, true); $email = $this->formatToAddresses(0, $email); $email = $this->formatConfidential(0, $email); $this->view->email = $email; } + return; } @@ -69,9 +70,9 @@ function ($dataArr) { $this->emailqueue, 'system/email/queue/view', $conditions, - ['status', 'priority', 'sent_on', 'to_addresses', 'subject'], + ['status', 'priority', 'confidential', 'from', 'to_addresses', 'subject', 'sent_on'], true, - ['status', 'priority', 'sent_on', 'to_addresses', 'subject'], + ['status', 'priority', 'confidential', 'from', 'to_addresses', 'subject', 'sent_on'], $controlActions, null, $replaceColumns, @@ -86,6 +87,7 @@ protected function replaceColumns($dataArr) foreach ($dataArr as $dataKey => &$data) { $data = $this->formatStatus($dataKey, $data); $data = $this->formatPriority($dataKey, $data); + $data = $this->formatConfidential($dataKey, $data); $data = $this->formatSentOn($dataKey, $data); $data = $this->formatToAddresses($dataKey, $data); $data = $this->addRequeueButton($dataKey, $data); @@ -120,14 +122,18 @@ protected function formatPriority($rowId, $data) return $data; } - protected function formatSentOn($rowId, $data) + protected function formatSentOn($rowId, $data, $id = null) { if (!$data['sent_on']) { - $data['sent_on'] = - ' - - Send Now - '; + if ($id) { + $data['sent_on'] = '-'; + } else { + $data['sent_on'] = + ' + + Send Now + '; + } } return $data; @@ -139,7 +145,16 @@ protected function formatToAddresses($rowId, $data) $data['to_addresses'] = $this->helper->decode($data['to_addresses'], true); } - $data['to_addresses'] = implode(',', $data['to_addresses']); + $toAddresses = []; + foreach ($data['to_addresses'] as $toAddress) { + if (isset($toAddress['email']) && isset($toAddress['name'])) { + array_push($toAddresses, $toAddress['email'] . '|' . $toAddress['name']); + } else { + array_push($toAddresses, $toAddress); + } + } + + $data['to_addresses'] = implode(',', $toAddresses); return $data; } @@ -151,6 +166,8 @@ protected function formatConfidential($rowId, $data) $data['body'] = "Confidential emails are encrypted on the server and cannot be viewed."; } else if ($data['confidential'] == '0') { $data['confidential'] = 'No'; + } else { + $data['confidential'] = 'No'; } return $data; @@ -172,26 +189,11 @@ protected function addRequeueButton($rowId, $data) /** * @acl(name="update") */ - public function changePriorityAction() - { - $this->requestIsPost(); - - $this->emailqueue->changePriority($this->postData()); - - $this->addResponse( - $this->emailqueue->packagesData->responseMessage, - $this->emailqueue->packagesData->responseCode - ); - } - - /** - * @acl(name="remove") - */ - public function removeAction() + public function updateAction() { $this->requestIsPost(); - $this->emailqueue->removeEmailService($this->postData()); + $this->emailqueue->updateQueue($this->postData()); $this->addResponse( $this->emailqueue->packagesData->responseMessage, @@ -227,7 +229,7 @@ public function processQueueAction() ); } - public function requeueAction() + public function reQueueAction() { $this->requestIsPost(); diff --git a/apps/Core/Components/System/Email/Services/ServicesComponent.php b/apps/Core/Components/System/Email/Services/ServicesComponent.php index 3165b5102..d44f13fc3 100644 --- a/apps/Core/Components/System/Email/Services/ServicesComponent.php +++ b/apps/Core/Components/System/Email/Services/ServicesComponent.php @@ -11,9 +11,15 @@ class ServicesComponent extends BaseComponent protected $emailservices; - public function initialize() + public function initialize($onlyActivityLogs = false) { $this->emailservices = $this->basepackages->emailservices; + + $this->setActivityLogsPackage($this->emailservices, 'system/email/services/activitylogs', [], ['password' => '*****']); + + if ($onlyActivityLogs) { + return; + } } /** @@ -31,6 +37,7 @@ public function viewAction() $this->view->emailservice = $emailservice; } + $this->view->pick('services/view'); return; diff --git a/apps/Core/Components/System/Filters/FiltersComponent.php b/apps/Core/Components/System/Filters/FiltersComponent.php index 545dcd230..77ac5ff15 100644 --- a/apps/Core/Components/System/Filters/FiltersComponent.php +++ b/apps/Core/Components/System/Filters/FiltersComponent.php @@ -11,6 +11,8 @@ class FiltersComponent extends BaseComponent protected $filters; + protected $components; + public function initialize() { $this->filters = $this->basepackages->filters; @@ -53,26 +55,13 @@ public function viewAction() if ($this->request->isPost()) { $replaceColumns = - [ - 'filter_type' => ['html' => - [ - '0' => 'System', - '1' => 'User' - ] - ], - 'is_default' => ['html' => - [ - '0' => 'No', - '1' => 'Yes' - ] - ], - 'auto_generated' => ['html' => - [ - '0' => 'No', - '1' => 'Yes' - ] - ] - ]; + function ($dataArr) { + if ($dataArr && is_array($dataArr) && count($dataArr) > 0) { + return $this->replaceColumns($dataArr); + } + + return $dataArr; + }; } else { $replaceColumns = null; } @@ -90,11 +79,11 @@ public function viewAction() $this->filters, 'system/filters/view', null, - ['name', 'app_type', 'filter_type', 'auto_generated', 'is_default'], + ['name', 'app_type', 'component_id', 'filter_type', 'is_default', 'auto_generated'], true, - ['name', 'app_type', 'filter_type', 'auto_generated', 'is_default'], + ['name', 'app_type', 'component_id', 'filter_type', 'is_default', 'auto_generated'], $controlActions, - null, + ['component_id'=>'Component (id)'], $replaceColumns, 'name' ); @@ -102,6 +91,66 @@ public function viewAction() $this->view->pick('filters/list'); } + protected function replaceColumns($dataArr) + { + foreach ($dataArr as $dataKey => &$data) { + $data = $this->formatComponentId($dataKey, $data); + $data = $this->formatFilterType($dataKey, $data); + $data = $this->formatIsDefault($dataKey, $data); + $data = $this->formatAutogenerated($dataKey, $data); + } + + return $dataArr; + } + + protected function formatComponentId($rowId, $data) + { + if (!isset($this->components[$data['component_id']])) { + $component = $this->modules->components->getById($data['component_id']); + } else { + $component = $this->components[$data['component_id']]; + } + + if ($component) { + $data['component_id'] = $component['name'] . ' (' . $component['id'] . ')'; + } + + return $data; + } + + protected function formatFilterType($rowId, $data) + { + if ($data['filter_type'] == '0') { + $data['filter_type'] = 'System (' . $data['filter_type'] . ')'; + } else if ($data['filter_type'] == '1') { + $data['filter_type'] = 'User (' . $data['filter_type'] . ')'; + } + + return $data; + } + + protected function formatIsDefault($rowId, $data) + { + if ($data['is_default'] == '0') { + $data['is_default'] = 'No (' . $data['is_default'] . ')'; + } else if ($data['is_default'] == '1') { + $data['is_default'] = 'Yes (' . $data['is_default'] . ')'; + } + + return $data; + } + + protected function formatAutogenerated($rowId, $data) + { + if ($data['auto_generated'] == '0') { + $data['auto_generated'] = 'No (' . $data['auto_generated'] . ')'; + } else if ($data['auto_generated'] == '1') { + $data['auto_generated'] = 'Yes (' . $data['auto_generated'] . ')'; + } + + return $data; + } + /** * @acl(name=add) */ @@ -207,4 +256,4 @@ public function getdefaultfilterAction() $this->filters->packagesData->responseCode ); } -} \ No newline at end of file +} diff --git a/apps/Core/Components/System/Geo/Cities/CitiesComponent.php b/apps/Core/Components/System/Geo/Cities/CitiesComponent.php index 86b7bab22..d33abde1c 100644 --- a/apps/Core/Components/System/Geo/Cities/CitiesComponent.php +++ b/apps/Core/Components/System/Geo/Cities/CitiesComponent.php @@ -21,8 +21,8 @@ public function initialize() */ public function viewAction() { - $countriesArr = $this->basepackages->geoCountries->getAll()->geoCountries; - $statesArr = $this->basepackages->geoStates->getAll()->geoStates; + $countriesArr = $this->basepackages->geoCountries->geoCountries; + $statesArr = $this->basepackages->geoStates->geoStates; if (isset($this->getData()['id'])) { if ($this->getData()['id'] != 0) { @@ -48,7 +48,7 @@ public function viewAction() // 'includeQ' => true, 'actionsToEnable' => [ - 'view' => 'system/geo/cities', + 'edit' => 'system/geo/cities', ] ]; @@ -87,11 +87,11 @@ public function viewAction() $this->geoCities, 'system/geo/cities/view', null, - ['name', 'longitude', 'latitude', 'postcode', 'state_id', 'country_id'], + ['name', 'longitude', 'latitude', 'state_id', 'country_id'], true, - ['name', 'longitude', 'latitude', 'postcode', 'state_id', 'country_id'], + ['name', 'longitude', 'latitude', 'state_id', 'country_id'], $controlActions, - ['state_id'=>'State','postcode'=>'post code', 'country_id'=>'country'], + ['state_id'=>'State','country_id'=>'country'], $replaceColumns, 'name', // $dtAdditionControlButtons @@ -152,27 +152,4 @@ public function searchCityAction() $this->addResponse('Search Query Missing', 1); } } - - public function searchPostCodeAction() - { - $this->requestIsPost(); - - if ($this->postData()['search']) { - $searchQuery = $this->postData()['search']; - - if (strlen($searchQuery) < 3) { - return; - } - - $this->basepackages->geoCities->searchPostCodes($searchQuery); - - $this->addResponse( - $this->basepackages->geoCities->packagesData->responseMessage, - $this->basepackages->geoCities->packagesData->responseCode, - $this->basepackages->geoCities->packagesData->responseData ?? [] - ); - } else { - $this->addResponse('Search Query Missing', 1); - } - } } \ No newline at end of file diff --git a/apps/Core/Components/System/Geo/Holidays/HolidaysComponent.php b/apps/Core/Components/System/Geo/Holidays/HolidaysComponent.php index 23e8fd12c..e294b32a7 100644 --- a/apps/Core/Components/System/Geo/Holidays/HolidaysComponent.php +++ b/apps/Core/Components/System/Geo/Holidays/HolidaysComponent.php @@ -4,6 +4,7 @@ use Apps\Core\Packages\Adminltetags\Traits\DynamicTable; use System\Base\BaseComponent; +use System\Base\Providers\BasepackagesServiceProvider\Packages\Geo\GeoHolidays; class HolidaysComponent extends BaseComponent { @@ -51,7 +52,7 @@ public function viewAction() return $this->throwIdNotFound(); } - $holidayTagsArr = $this->basepackages->tags->getTagsByPackageNameAndPackageRowId('GeoHolidays', $holiday['id']); + $holidayTagsArr = $this->basepackages->tags->getTagsByPackageClassAndPackageRowId(str_replace('\\', '_', GeoHolidays::Class), $holiday['id']); if (count($holidayTagsArr) > 0) { foreach ($holidayTagsArr as $tag) { @@ -68,7 +69,7 @@ public function viewAction() $this->view->holidayTags = $holidayTags; - $this->view->tags = $this->basepackages->tags->getTagsByPackageName('GeoHolidays'); + $this->view->tags = $this->basepackages->tags->getTagsByPackageClass(str_replace('\\', '_', GeoHolidays::Class)); $this->view->pick('holidays/view'); @@ -87,6 +88,8 @@ public function viewAction() $replaceColumns = function ($dataArr) { if ($dataArr && is_array($dataArr) && count($dataArr) > 0) { + $states = []; + foreach ($dataArr as &$data) { if ($data['is_national_holiday'] == '1') { $data['is_national_holiday'] = 'Yes'; @@ -94,9 +97,17 @@ function ($dataArr) { } else { $data['is_national_holiday'] = 'No'; - $state = $this->basepackages->geoStates->getById($data['state_id']); + if (isset($states[$data['state_id']])) { + $state = $states[$data['state_id']]; + } else { + $state = $this->basepackages->geoStates->getById($data['state_id']); + } if ($state) { + if (!isset($states[$state['id']])) { + $states[$state['id']] = $state; + } + $data['state_id'] = $state['name']; } else { $data['state_id'] = '-'; diff --git a/apps/Core/Components/System/Geo/Postcodes/Install/component.json b/apps/Core/Components/System/Geo/Postcodes/Install/component.json new file mode 100644 index 000000000..01d8e1d10 --- /dev/null +++ b/apps/Core/Components/System/Geo/Postcodes/Install/component.json @@ -0,0 +1,59 @@ +{ + "name" : "Geo Postcodes", + "route" : "system/geo/postcodes", + "description" : "Manage geo postcodes via this component
", + "module_type" : "components", + "app_type" : "core", + "category" : "admin", + "version" : "0.0.0", + "repo" : "https://.../", + "class" : "Apps\\Core\\Components\\System\\Geo\\Postcodes\\PostcodesComponent", + "dependencies" : + { + "core" : + { + "name" : "Core", + "version" : "0.0.0", + "repo" : "https://.../" + }, + "components" : [], + "packages" : [], + "middlewares" : [], + "views" : [], + "external" : [], + "externals" : [] + }, + "menu" : + { + "seq" : 6, + "system" : + { + "icon" : "cogs", + "title" : "system", + "childs" : + { + "geolocations" : + { + "title" : "Geo Locations", + "icon" : "globe", + "childs" : + { + "postcodes" : + { + "title" : "Postcodes", + "link" : "system/geo/postcodes" + } + } + } + } + } + }, + "widgets" : [], + "settings" : + { + "mandatory" : + { + "core" : true + } + } +} \ No newline at end of file diff --git a/apps/Core/Components/System/Geo/Postcodes/PostcodesComponent.php b/apps/Core/Components/System/Geo/Postcodes/PostcodesComponent.php new file mode 100644 index 000000000..56266fca8 --- /dev/null +++ b/apps/Core/Components/System/Geo/Postcodes/PostcodesComponent.php @@ -0,0 +1,177 @@ +geoPostcodes = $this->basepackages->geoPostcodes->init(); + } + + /** + * @acl(name=view) + */ + public function viewAction() + { + $statesArr = $this->basepackages->geoStates->geoStates; + $countriesArr = $this->basepackages->geoCountries->geoCountries; + + if (isset($this->getData()['id'])) { + if ($this->getData()['id'] != 0) { + $postcode = $this->basepackages->geoPostcodes->getById($this->getData()['id']); + + $this->view->postcode = $postcode; + } + + if (!$this->view->postcode) { + return $this->throwIdNotFound(); + } + + $this->view->pick('postcodes/view'); + + $this->view->countries = [$countriesArr[$postcode['country_id']]]; + $this->view->states = [$statesArr[$postcode['state_id']]]; + + return; + } + + $controlActions = + [ + // 'includeQ' => true, + 'actionsToEnable' => + [ + 'edit' => 'system/geo/postcodes', + ] + ]; + + if ($this->request->isPost()) { + $countries = []; + $states = []; + + if ($countriesArr) { + foreach ($countriesArr as $countriesKey => $country) { + $countries[$country['id']] = $country['name'] . ' (' . $country['id'] . ')'; + } + } + + if ($statesArr) { + foreach ($statesArr as $statesKey => $state) { + $states[$state['id']] = $state['name'] . ' (' . $state['id'] . ')'; + } + } + + $replaceColumns = + [ + 'state_id' => + [ + 'html' => $states + ], + 'country_id' => + [ + 'html' => $countries + ], + ]; + } else { + $replaceColumns = []; + } + + $this->generateDTContent( + $this->geoPostcodes, + 'system/geo/postcodes/view', + null, + ['code', 'name', 'state_id', 'country_id'], + true, + ['code', 'name', 'state_id', 'country_id'], + $controlActions, + ['code'=>'post code','state_id'=>'State','country_id'=>'country'], + $replaceColumns, + 'code' + ); + + $this->view->pick('postcodes/list'); + } + + /** + * @acl(name=add) + */ + public function addAction() + { + $this->requestIsPost(); + + $this->geoPostcodes->addPostcode($this->postData()); + + $this->addResponse( + $this->geoPostcodes->packagesData->responseMessage, + $this->geoPostcodes->packagesData->responseCode + ); + } + + /** + * @acl(name=update) + */ + public function updateAction() + { + $this->requestIsPost(); + + $this->geoPostcodes->updatePostcode($this->postData()); + + $this->addResponse( + $this->geoPostcodes->packagesData->responseMessage, + $this->geoPostcodes->packagesData->responseCode + ); + } + + public function searchPostcodeAction() + { + $this->requestIsPost(); + + if ($this->postData()['search']) { + $searchQuery = $this->postData()['search']; + + if (strlen($searchQuery) < 3) { + return; + } + + $this->basepackages->geoPostcodes->searchPostcodes($searchQuery); + + $this->addResponse( + $this->basepackages->geoPostcodes->packagesData->responseMessage, + $this->basepackages->geoPostcodes->packagesData->responseCode, + $this->basepackages->geoPostcodes->packagesData->responseData ?? [] + ); + } else { + $this->addResponse('Search Query Missing', 1); + } + } + + public function searchPostCodeNameAction() + { + $this->requestIsPost(); + + if ($this->postData()['search']) { + $searchQuery = $this->postData()['search']; + + if (strlen($searchQuery) < 3) { + return; + } + + $this->basepackages->geoPostcodes->searchPostCodes($searchQuery); + + $this->addResponse( + $this->basepackages->geoPostcodes->packagesData->responseMessage, + $this->basepackages->geoPostcodes->packagesData->responseCode, + $this->basepackages->geoPostcodes->packagesData->responseData ?? [] + ); + } else { + $this->addResponse('Search Query Missing', 1); + } + } +} \ No newline at end of file diff --git a/apps/Core/Components/System/Geo/Regions/RegionsComponent.php b/apps/Core/Components/System/Geo/Regions/RegionsComponent.php index 7919a57bd..da04dabc2 100644 --- a/apps/Core/Components/System/Geo/Regions/RegionsComponent.php +++ b/apps/Core/Components/System/Geo/Regions/RegionsComponent.php @@ -21,7 +21,7 @@ public function initialize() */ public function viewAction() { - $regionsArr = $this->basepackages->geoRegions->getAll()->geoRegions; + $regionsArr = $this->basepackages->geoRegions->geoRegions; if (isset($this->getData()['id'])) { if ($this->getData()['id'] != 0) { diff --git a/apps/Core/Components/System/Geo/States/StatesComponent.php b/apps/Core/Components/System/Geo/States/StatesComponent.php index 6e2495d80..95f5a7818 100644 --- a/apps/Core/Components/System/Geo/States/StatesComponent.php +++ b/apps/Core/Components/System/Geo/States/StatesComponent.php @@ -21,7 +21,7 @@ public function initialize() */ public function viewAction() { - $countriesArr = $this->basepackages->geoCountries->getAll()->geoCountries; + $countriesArr = $this->basepackages->geoCountries->geoCountries; if (isset($this->getData()['id'])) { if ($this->getData()['id'] != 0) { @@ -46,7 +46,7 @@ public function viewAction() // 'includeQ' => true, 'actionsToEnable' => [ - 'view' => 'system/geo/states', + 'edit' => 'system/geo/states', ] ]; @@ -73,9 +73,9 @@ public function viewAction() $this->geoStates, 'system/geo/states/view', null, - ['name', 'state_code', 'country_id'], + ['name', 'country_id'], true, - ['name', 'state_code', 'country_id'], + ['name', 'country_id'], $controlActions, null, $replaceColumns, @@ -91,7 +91,14 @@ public function viewAction() */ public function addAction() { - // + $this->requestIsPost(); + + $this->geoStates->addState($this->postData()); + + $this->addResponse( + $this->geoStates->packagesData->responseMessage, + $this->geoStates->packagesData->responseCode + ); } /** @@ -99,7 +106,14 @@ public function addAction() */ public function updateAction() { - // + $this->requestIsPost(); + + $this->geoStates->updateState($this->postData()); + + $this->addResponse( + $this->geoStates->packagesData->responseMessage, + $this->geoStates->packagesData->responseCode + ); } public function searchStateAction() diff --git a/apps/Core/Components/System/Geo/Timezones/Widgets.php b/apps/Core/Components/System/Geo/Timezones/Widgets.php index 88c8ed925..f2118531e 100644 --- a/apps/Core/Components/System/Geo/Timezones/Widgets.php +++ b/apps/Core/Components/System/Geo/Timezones/Widgets.php @@ -9,7 +9,7 @@ class Widgets extends ComponentsWidgets { public function worldClock($widget, $dashboardWidget) { - $timezonesArr = $this->componentObj->getDi()->getShared('basepackages')->geoTimezones->getAll()->geoTimezones; + $timezonesArr = $this->componentObj->getDi()->getShared('basepackages')->geoTimezones->geoTimezones; $timezones = []; foreach ($timezonesArr as $timezone) { diff --git a/apps/Core/Components/System/Menus/MenusComponent.php b/apps/Core/Components/System/Menus/MenusComponent.php index d98120d79..705e4e5af 100644 --- a/apps/Core/Components/System/Menus/MenusComponent.php +++ b/apps/Core/Components/System/Menus/MenusComponent.php @@ -44,6 +44,7 @@ public function viewAction() 'actionsToEnable' => [ 'view' => 'system/menus', + 'remove' => 'system/menus/remove', ] ]; @@ -57,7 +58,7 @@ public function viewAction() $controlActions, null, null, - 'id' + 'route' ); $this->view->pick('menus/list'); @@ -84,6 +85,13 @@ public function updateAction() */ public function removeAction() { - // + $this->requestIsPost(); + + $removeMenu = $this->menus->removeMenu($this->postData()); + + $this->addResponse( + $this->menus->packagesData->responseMessage, + $this->menus->packagesData->responseCode + ); } } \ No newline at end of file diff --git a/apps/Core/Components/System/Mutex/Install/component.json b/apps/Core/Components/System/Mutex/Install/component.json new file mode 100644 index 000000000..bd11f1731 --- /dev/null +++ b/apps/Core/Components/System/Mutex/Install/component.json @@ -0,0 +1,53 @@ +{ + "name" : "Mutex Lock", + "route" : "system/mutex", + "description" : "Manage mutex lock data via this component
", + "module_type" : "components", + "app_type" : "core", + "category" : "admin", + "version" : "0.0.0", + "repo" : "https://.../", + "class" : "Apps\\Core\\Components\\System\\Mutex\\MutexComponent", + "dependencies" : + { + "core" : + { + "name" : "Core", + "version" : "0.0.0", + "repo" : "https://.../" + }, + "components" : [], + "packages" : [], + "middlewares" : [], + "views" : [], + "external" : [], + "externals" : [] + }, + "menu" : + { + "system" : + { + "title" : "system", + "icon" : "cogs", + "childs" : + { + "mutexlock" : + { + "title" : "mutex lock", + "icon" : "lock", + "link" : "system/mutex" + } + } + }, + "seq" : "0" + }, + "widgets" : [], + "filters" : [], + "settings" : + { + "mandatory" : + { + "core" : true + } + } +} \ No newline at end of file diff --git a/apps/Core/Components/System/Mutex/MutexComponent.php b/apps/Core/Components/System/Mutex/MutexComponent.php new file mode 100644 index 000000000..f434e1685 --- /dev/null +++ b/apps/Core/Components/System/Mutex/MutexComponent.php @@ -0,0 +1,105 @@ +mutex = $this->basepackages->mutex; + } + + /** + * @acl(name=view) + */ + public function viewAction() + { + $controlActions = + [ + // 'disableActionsForIds' => [1], + 'actionsToEnable' => + [ + 'remove' => 'system/mutex/remove' + ] + ]; + + $replaceColumns = + function ($dataArr) { + if ($dataArr && is_array($dataArr) && count($dataArr) > 0) { + return $this->replaceColumns($dataArr); + } + + return $dataArr; + }; + + $this->generateDTContent( + $this->mutex, + 'system/mutex/view', + null, + ['package_class', 'package_row_id', 'parent_lock_id', 'locked_at', 'account_id'], + false, + ['package_class', 'package_row_id', 'parent_lock_id', 'locked_at', 'account_id'], + null, + ['parent_lock_id' => 'Locked By (Mutex ID)', 'locked_at' => 'Locked At | Release At'], + $replaceColumns, + 'package_row_id' + ); + + $this->view->pick('mutex/list'); + } + + protected function replaceColumns($dataArr) + { + foreach ($dataArr as $dataKey => &$data) { + if (isset($data['locked_at']) && $data['locked_at'] > 0) { + $releaseTime = $data['locked_at'] + $this->mutex->getTimeout(); + $data['locked_at'] = (\Carbon\Carbon::parse($data['locked_at']))->toAtomString(); + $data['locked_at'] = $data['locked_at'] . ' | ' . (\Carbon\Carbon::parse($releaseTime))->toAtomString(); + } + + $account = $this->basepackages->accounts->getAccountById($data['account_id']); + + if ($account && isset($account['contact']['full_name'])) { + $data['account_id'] = $account['contact']['full_name']; + } + + $data = $this->generateRemoveButton($dataKey, $data); + } + + return $dataArr; + } + + protected function generateRemoveButton($rowId, $data) + { + if ($data['parent_lock_id'] == '0') { + $data['parent_lock_id'] = + ' + Remove lock + '; + } + + return $data; + } + + /** + * @acl(name="remove") + */ + public function removeAction() + { + $this->requestIsPost(); + + $this->mutex->releaseMutex($this->postData()); + + $this->addResponse( + $this->mutex->packagesData->responseMessage, + $this->mutex->packagesData->responseCode + ); + } +} \ No newline at end of file diff --git a/apps/Core/Components/System/Notifications/NotificationsComponent.php b/apps/Core/Components/System/Notifications/NotificationsComponent.php index 340d258ec..340e6f84a 100644 --- a/apps/Core/Components/System/Notifications/NotificationsComponent.php +++ b/apps/Core/Components/System/Notifications/NotificationsComponent.php @@ -52,6 +52,17 @@ function ($dataArr) { return $dataArr; }; + $quickFilterConditions = function() { + if (str_contains($this->postData()['conditions'], 'account_id')) { + throw new \Exception('Cannot access other users data!'); + } + + return + str_replace( + '-|', '-|app_id|equals|' . $this->apps->getAppInfo()['id'] . '&and|account_id|equals|' . $this->access->auth->account()['id'] . '&and|' , $this->postData()['conditions'] + ); + }; + $this->generateDTContent( $this->notifications, 'system/notifications/view', @@ -75,7 +86,10 @@ function ($dataArr) { false, null, false, - false + false, + [], + [], + $quickFilterConditions ); $this->view->pick('notifications/list'); @@ -132,13 +146,15 @@ protected function packageLinks() { $routeLinks = []; - foreach ($this->modules->packages->packages as $packageKey => $package) { + $packages = $this->modules->packages->getPackagesForAppType($this->app['app_type']); + + foreach ($packages as $packageKey => $package) { if ($package['settings'] && $package['settings'] !== '' && $package['settings'] !== '[]') { - if (is_string($package['settings'])) { + if (!is_array($package['settings'])) { $package['settings'] = $this->helper->decode($package['settings'], true); } if (isset($package['settings']['componentRoute'])) { - $routeLinks[$package['name']] = $package['settings']['componentRoute']; + $routeLinks[strtolower($package['name'])] = strtolower($package['settings']['componentRoute']); } } } @@ -152,7 +168,7 @@ protected function generateUserInfo($rowId, $data) $profile = $this->basepackages->profiles->getProfile($data['created_by']); if ($profile) { - $data['created_by'] = $profile['full_name']; + $data['created_by'] = $profile['contact']['full_name']; } else { $data['created_by'] = 'System'; } @@ -166,12 +182,18 @@ protected function generateUserInfo($rowId, $data) protected function generateLinkButton($rowId, $data) { if ($data['package_row_id']) { - if (array_key_exists($data['package_name'], $this->packageLinks())) { - $data['package_row_id'] = - ' - - '; + $link = '#'; + + if (array_key_exists(strtolower($data['package_name']), $this->packageLinks())) { + $link = $this->links->url($this->packageLinks()[strtolower($data['package_name'])] . '/q/id/' . $data['package_row_id']); + } else if ($key = array_search(strtolower($data['package_name']), $this->packageLinks())) { + $link = $this->links->url($this->packageLinks()[$key] . '/q/id/' . $data['package_row_id']); } + + $data['package_row_id'] = + ' + + '; } return $data; diff --git a/apps/Core/Components/System/Storages/StoragesComponent.php b/apps/Core/Components/System/Storages/StoragesComponent.php index 77fd8ed56..52d4cde8b 100644 --- a/apps/Core/Components/System/Storages/StoragesComponent.php +++ b/apps/Core/Components/System/Storages/StoragesComponent.php @@ -13,7 +13,7 @@ class StoragesComponent extends BaseComponent public function initialize() { - $this->setModuleSettings(true); + $this->setModuleSettings(); $this->storages = $this->usePackage('storages'); } diff --git a/apps/Core/Components/System/Tags/TagsComponent.php b/apps/Core/Components/System/Tags/TagsComponent.php index e61056e27..d492ca22b 100644 --- a/apps/Core/Components/System/Tags/TagsComponent.php +++ b/apps/Core/Components/System/Tags/TagsComponent.php @@ -27,11 +27,17 @@ public function viewAction() if ($this->getData()['id'] != 0) { $tag = $this->basepackages->tags->getById((int) $this->getData()['id']); - $this->view->tag = $tag; - - if (!$this->view->tag) { + if (!$tag) { return $this->throwIdNotFound(); } + + $package = $this->modules->packages->getPackageByClass(str_replace('_', '\\', $tag['package_class'])); + + if ($package) { + $tag['package_class'] = $package['name']; + } + + $this->view->tag = $tag; } $this->view->pick('tags/view'); @@ -55,6 +61,12 @@ public function viewAction() function ($dataArr) { if ($dataArr && is_array($dataArr) && count($dataArr) > 0) { foreach ($dataArr as &$data) { + $package = $this->modules->packages->getPackageByClass(str_replace('_', '\\', $data['package_class'])); + + if ($package) { + $data['package_class'] = $package['display_name']; + } + $data['package_row_ids'] = count($data['package_row_ids']); $data['name'] = '' . $data['name'] . ''; } @@ -70,8 +82,8 @@ function ($dataArr) { package : $this->tags, postUrl : 'system/tags/view', postUrlParams : null, - columnsForTable : ['name', 'package_name', 'swatch', 'package_row_ids'], - columnsForFilter : ['name', 'package_name', 'swatch'], + columnsForTable : ['name', 'package_class', 'swatch', 'package_row_ids'], + columnsForFilter : ['name', 'package_class', 'swatch'], controlActions : $controlActions, dtReplaceColumnsTitle : ['package_row_ids' => '# of times used'], dtReplaceColumns :$replaceColumns, diff --git a/apps/Core/Components/System/Users/Accounts/AccountsComponent.php b/apps/Core/Components/System/Users/Accounts/AccountsComponent.php index 94e5b4d83..4edc36a34 100644 --- a/apps/Core/Components/System/Users/Accounts/AccountsComponent.php +++ b/apps/Core/Components/System/Users/Accounts/AccountsComponent.php @@ -7,6 +7,7 @@ use Apps\Core\Packages\Crms\Customers\Customers; use Apps\Core\Packages\Hrms\Employees\Employees; use System\Base\BaseComponent; +use System\Base\Providers\BasepackagesServiceProvider\Packages\Users\Profiles; class AccountsComponent extends BaseComponent { @@ -30,7 +31,7 @@ public function viewAction() { if (isset($this->getData()['id'])) { if ($this->getData()['id'] != 0) { - $account = $this->accounts->generateViewData($this->getData()['id']); + $account = $this->accounts->generateViewData((int) $this->getData()['id']); if (!$account) { return $this->throwIdNotFound(); @@ -42,7 +43,7 @@ public function viewAction() if ($account) { $app = $this->apps->getAppInfo(); - $middlewares = $this->modules->middlewares->getMiddlewaresForAppType($app['app_type'],null); + $middlewares = $this->modules->middlewares->middlewares; $middlewareEnabledForApps = []; @@ -66,6 +67,7 @@ public function viewAction() if (count($middlewareEnabledForApps) > 0) { $this->view->aclMiddlewareEnabled = true; + foreach ($components as $key => $component) { if (!in_array($component['id'], $middlewareEnabledForApps)) { unset($components[$key]); @@ -83,9 +85,9 @@ public function viewAction() $this->view->roles = $this->accounts->packagesData->roles; - $this->view->countries = $this->basepackages->geoCountries->getAll()->geoCountries; + $this->view->countries = $this->basepackages->geoCountries->geoCountries; - $this->view->timezones = $this->basepackages->geoTimezones->getAll()->geoTimezones; + $this->view->timezones = $this->basepackages->geoTimezones->geoTimezones; } $this->addResponse( @@ -124,11 +126,11 @@ function ($dataArr) { $this->accounts, 'system/users/accounts/view', null, - ['profile_package_row_id', 'status', 'email', 'username', 'role_id', 'first_name', 'last_name', 'profile_package_name'], + ['profile_package_row_id', 'status', 'email', 'username', 'role_id', 'first_name', 'last_name', 'profile_package_class'], true, ['status', 'email', 'username', 'role_id', 'first_name', 'last_name'], $controlActions, - ['role_id' => 'role (ID)', 'profile_package_name' => 'Used By', 'profile_package_row_id' => 'link'], + ['role_id' => 'role (ID)', 'profile_package_class' => 'Used By', 'profile_package_row_id' => 'link'], $replaceColumns, 'email' ); @@ -153,6 +155,13 @@ protected function replaceColumns($dataArr) } else { $data['status'] = 'ENABLED'; } + + if (!isset($data['first_name'])) { + $data['first_name'] = '-'; + } + if (!isset($data['last_name'])) { + $data['last_name'] = '-'; + } } return $dataArr; @@ -174,20 +183,35 @@ protected function getProfilesData($data, $rowId = null) $profile = null; $componentRoute = null; - $profilePackage = $this->modules->packages->getPackageByName($data['profile_package_name']); + $profilePackage = $this->modules->packages->getPackageByClass(str_replace('_', '\\', $data['profile_package_class'])); - if ($data['profile_package_name'] === 'UsersProfiles') { + if ($data['profile_package_class'] === str_replace('\\', '_', Profiles::class)) { $profile = $this->basepackages->profiles->getById($data['profile_package_row_id']); } else if ($profilePackage) { - //Get profile information from packages class. + try { + $profilePackageClass = new $profilePackage['class']; + + $profile = $profilePackageClass->getById($data['profile_package_row_id']); + } catch (\throwable $e) { + //Do nothing. + } } + $profilePackageClassArr = explode('_', $data['profile_package_class']); + if ($profilePackage) { - if (is_string($profilePackage['settings'])) { - $profilePackage['settings'] = $this->helper->decode($profilePackage['settings'], true); - } - if (isset($profilePackage['settings']['componentRoute'])) { - $componentRoute = $profilePackage['settings']['componentRoute']; + if ($data['profile_package_class'] === str_replace('\\', '_', Profiles::class) || + strtolower($profilePackageClassArr[1]) === $this->apps->getAppInfo()['app_type'] + ) { + if (isset($profilePackage['settings']) && + is_string($profilePackage['settings']) + ) { + $profilePackage['settings'] = $this->helper->decode($profilePackage['settings'], true); + } + + if (isset($profilePackage['settings']['componentRoute'])) { + $componentRoute = $profilePackage['settings']['componentRoute']; + } } } @@ -200,7 +224,12 @@ protected function getProfilesData($data, $rowId = null) } } else { $data['profile_package_row_id'] = '-'; - $data['profile_package_name'] = '-'; + } + + if ($data['profile_package_class'] === str_replace('\\', '_', Profiles::class)) { + $data['profile_package_class'] = 'Profiles'; + } else { + $data['profile_package_class'] = $profilePackageClassArr[1] . $this->helper->last($profilePackageClassArr); } return $data; diff --git a/apps/Core/Components/System/Users/Profile/ProfileComponent.php b/apps/Core/Components/System/Users/Profile/ProfileComponent.php index ce96cf0e3..2bd171b8f 100644 --- a/apps/Core/Components/System/Users/Profile/ProfileComponent.php +++ b/apps/Core/Components/System/Users/Profile/ProfileComponent.php @@ -60,9 +60,9 @@ public function viewAction() $this->view->canUse2fa = $this->profiles->packagesData->canUse2fa; - $this->view->countries = $this->basepackages->geoCountries->getAll()->geoCountries; + $this->view->countries = $this->basepackages->geoCountries->geoCountries; - $this->view->timezones = $this->basepackages->geoTimezones->getAll()->geoTimezones; + $this->view->timezones = $this->basepackages->geoTimezones->geoTimezones; $apis = $this->api->getApiInfo(false, true); $passwordApis = []; @@ -74,6 +74,15 @@ public function viewAction() } } $this->view->passwordApis = msort($passwordApis, 'id'); + + $accountEnv = $this->basepackages->accounts->checkEnv($this->access->auth->account()['id'], false, false, true); + if ($accountEnv && isset($accountEnv['params'][$this->apps->getAppInfo()['id']])) { + $accountEnv = $accountEnv['params'][$this->apps->getAppInfo()['id']]; + } else { + $accountEnv = []; + } + + $this->view->accountEnv = $accountEnv; } else { return; } @@ -192,4 +201,16 @@ public function removeAccountAgentsAction() $this->basepackages->accounts->packagesData->responseCode ); } + + public function removeEnvRouteParamsAction() + { + $this->requestIsPost(); + + $this->basepackages->accounts->removeEnvRouteParams($this->postData()); + + $this->addResponse( + $this->basepackages->accounts->packagesData->responseMessage, + $this->basepackages->accounts->packagesData->responseCode + ); + } } \ No newline at end of file diff --git a/apps/Core/Components/System/Workers/Jobs/JobsComponent.php b/apps/Core/Components/System/Workers/Jobs/JobsComponent.php index e4e7b11a8..b10a9066c 100644 --- a/apps/Core/Components/System/Workers/Jobs/JobsComponent.php +++ b/apps/Core/Components/System/Workers/Jobs/JobsComponent.php @@ -14,6 +14,8 @@ class JobsComponent extends BaseComponent public function initialize() { $this->jobs = $this->basepackages->workers->jobs; + + $this->tasks = $this->basepackages->workers->tasks; } /** @@ -29,6 +31,12 @@ public function viewAction() return $this->throwIdNotFound(); } + $task = $this->tasks->getById((int) $job['task_id']); + + if ($task) { + $this->view->task = $task; + } + $this->view->job = $job; } @@ -64,11 +72,11 @@ function ($dataArr) { $this->jobs, 'system/workers/jobs/view', $conditions, - ['task_id', 'worker_id', 'run_on', 'status', 'execution_time'], + ['task_id', 'worker_id', 'run_on', 'status', 'total_execution_time', 'can_terminate'], true, - ['task_id', 'worker_id', 'run_on', 'status', 'execution_time'], + ['task_id', 'worker_id', 'run_on', 'status', 'total_execution_time', 'can_terminate'], $controlActions, - ['task_id'=>'task', 'worker_id'=>'worker'], + ['task_id' => 'task', 'worker_id' => 'worker', 'can_terminate' => 'terminate'], $replaceColumns, 'id', null, @@ -86,6 +94,7 @@ protected function replaceColumns($dataArr) $data = $this->formatTask($dataKey, $data); $data = $this->formatWorker($dataKey, $data); $data = $this->formatRunon($dataKey, $data); + $data = $this->formatTerminate($dataKey, $data); $data = $this->formatStatus($dataKey, $data); } @@ -105,7 +114,7 @@ protected function formatStatus($rowId, $data) } else if ($data['status'] == '4') { $data['status'] = 'Error!'; } else if ($data['status'] == '5') { - $data['status'] = 'Rescheduled!'; + $data['status'] = 'Rescheduled (No worker)'; } return $data; @@ -143,10 +152,49 @@ protected function formatRunon($rowId, $data) $data['run_on'] = $this->helper->decode($data['run_on']); } - if (is_array($data['run_on']) && isset($data['run_on'][0])) { - $data['run_on'] = $data['run_on'][0]; + if ($data['run_on'] && is_array($data['run_on'])) { + $data['run_on'] = $this->helper->last($data['run_on']); + } + + return $data; + } + + protected function formatTerminate($rowId, $data) + { + if ($data['can_terminate'] && $data['status'] == '2') { + $data['can_terminate'] = + ' + + '; + } else { + $data['can_terminate'] = '-'; } return $data; } + + public function terminateAction() + { + $this->requestIsPost(); + + $this->jobs->terminateJob($this->postData()); + + $this->addResponse( + $this->jobs->packagesData->responseMessage, + $this->jobs->packagesData->responseCode + ); + } + + public function getJobLogsAction() + { + $this->requestIsPost(); + + $this->jobs->getJobLogs($this->postData()); + + $this->addResponse( + $this->jobs->packagesData->responseMessage, + $this->jobs->packagesData->responseCode, + $this->jobs->packagesData->responseData ?? [], + ); + } } \ No newline at end of file diff --git a/apps/Core/Components/System/Workers/Tasks/TasksComponent.php b/apps/Core/Components/System/Workers/Tasks/TasksComponent.php index 5453412b4..d21b24306 100644 --- a/apps/Core/Components/System/Workers/Tasks/TasksComponent.php +++ b/apps/Core/Components/System/Workers/Tasks/TasksComponent.php @@ -29,6 +29,8 @@ public function viewAction() { $this->schedules = $this->basepackages->workers->schedules->schedules; + $this->view->jobLogsModes = $this->tasks->getJobLogsModes(); + if (isset($this->getData()['id'])) { $calls = []; @@ -52,14 +54,14 @@ public function viewAction() $this->tasks->setFFRelations(true); - // $calls = $this->tasks->getAllCalls(); - $this->view->calls = $calls; $this->view->schedules = $this->schedules; + $this->view->emailservices = $this->basepackages->emailservices->getAll()->emailServices; + if ($this->getData()['id'] != 0) { - $task = $this->tasks->getById($this->getData()['id']); + $task = $this->tasks->getById((int) $this->getData()['id']); if (!$task) { return $this->throwIdNotFound(); @@ -176,7 +178,7 @@ protected function formatSchedule($rowId, $data, $schedulesArr) protected function formatStatus($rowId, $data) { - if ($data['enabled'] == '0' && $data['status'] != '2') { + if ($data['enabled'] == '0' && $data['is_on_demand'] == '0') { $data['status'] = '-'; return $data; @@ -189,11 +191,11 @@ protected function formatStatus($rowId, $data) } else if ($data['status'] == '2') { $data['status'] = 'Running...'; } else if ($data['status'] == '3') { + $data['status'] = 'Success!'; + } else if ($data['status'] == '4') { $data['status'] = 'Error!'; - } - - if ($data['force_next_run'] == '1') { - return $data; + } else if ($data['status'] == '5') { + $data['status'] = 'Rescheduled (no workers)'; } return $data; diff --git a/apps/Core/Components/Viewssettings/ViewssettingsComponent.php b/apps/Core/Components/Viewssettings/ViewssettingsComponent.php index cf639040b..c212bc12b 100644 --- a/apps/Core/Components/Viewssettings/ViewssettingsComponent.php +++ b/apps/Core/Components/Viewssettings/ViewssettingsComponent.php @@ -20,6 +20,8 @@ public function initialize() public function viewAction() { if (isset($this->getData()['id'])) { + $this->useStorage('public'); + if ($this->getData()['id'] != 0) { $viewssettings = $this->modules->viewsSettings->getViewsSettingsById($this->getData()['id']); @@ -41,9 +43,14 @@ public function viewAction() if ($views) { foreach ($views as $viewKey => $view) { + if ($view['is_subview']) { + continue; + } + $apps[$value['id']]['views'][$view['id']]['id'] = $view['id']; $apps[$value['id']]['views'][$view['id']]['name'] = $view['name']; $apps[$value['id']]['views'][$view['id']]['display_name'] = $view['display_name']; + if (is_string($view['settings'])) { $view['settings'] = $this->helper->decode($view['settings'], true); } @@ -52,7 +59,6 @@ public function viewAction() is_array($view['settings']['branding']) ) { foreach ($view['settings']['branding'] as $brandKey => $brand) { - if (is_array($brand) && !isset($brand['brand'])) { // we unset it as branding is not correct. unset($view['settings']['branding'][$brandKey]); @@ -68,6 +74,7 @@ public function viewAction() } } } + $apps[$value['id']]['views'][$view['id']]['settings'] = $view['settings']; } } @@ -112,8 +119,25 @@ public function viewAction() $views = [$apps[$viewssettings['app_id']]['views'][$viewssettings['view_id']]]; } + $activeViewLayout = 'default'; + + if (isset($viewssettings['settings']['layouts']) && + is_array($viewssettings['settings']['layouts']) + ) { + foreach ($viewssettings['settings']['layouts'] as $layout) { + if (isset($layout['active']) && $layout['active'] == 'true') { + $activeViewLayout = $layout['view']; + + break; + } + } + } else { + $viewssettings['settings']['layouts'] = []; + } + $this->view->views = $views; $this->view->viewssettings = $viewssettings; + $this->view->activeViewLayout = $activeViewLayout; } else { $this->view->viewssettings = []; } diff --git a/apps/Core/Install/type.json b/apps/Core/Install/type.json index 1e2eb3d7a..873659409 100644 --- a/apps/Core/Install/type.json +++ b/apps/Core/Install/type.json @@ -1,6 +1,5 @@ { "app_type" : "core", - "dashboards" : true, "name" : "Core", "description" : "Core apps type for core modules.", "version" : "0.0.0", diff --git a/apps/Core/Middlewares/Acl/Acl.php b/apps/Core/Middlewares/Acl/Acl.php index f7a1f60cb..6962e12ec 100644 --- a/apps/Core/Middlewares/Acl/Acl.php +++ b/apps/Core/Middlewares/Acl/Acl.php @@ -25,8 +25,6 @@ class Acl extends BaseMiddleware protected $accountPermissions; - protected $rolePermissions; - protected $found = false; protected $isApi = false; @@ -41,7 +39,7 @@ public function process($data) } $this->actions = - ['view', 'add', 'update', 'remove', 'msview', 'msupdate']; + ['view', 'add', 'update', 'remove', 'msview', 'msupdate', 'activitylogs']; $rolesArr = $this->basepackages->roles->getAll()->roles; $roles = []; @@ -152,14 +150,15 @@ public function process($data) ); if (is_string($this->role['permissions'])) { - $this->rolePermissions = $this->helper->decode($this->role['permissions'], true); - } else { - $this->rolePermissions = $this->role['permissions']; + $this->role['permissions'] = $this->helper->decode($this->role['permissions'], true); } - foreach ($this->rolePermissions as $appKey => $app) { + + foreach ($this->role['permissions'] as $appKey => $app) { foreach ($app as $componentKey => $permission) { if ($this->app['id'] == $appKey) { - if ($this->components[$componentKey]['route'] === $this->controllerRoute) { + if (isset($this->components[$componentKey]) && + $this->components[$componentKey]['route'] === $this->controllerRoute + ) { if (($this->isApi && $this->helper->has($this->components[$componentKey]['api_acls'], $this->action)) || (!$this->isApi && $this->helper->has($this->components[$componentKey]['acls'], $this->action)) ) { diff --git a/apps/Core/Middlewares/Auth/Auth.php b/apps/Core/Middlewares/Auth/Auth.php index c598305e1..23c8904f0 100644 --- a/apps/Core/Middlewares/Auth/Auth.php +++ b/apps/Core/Middlewares/Auth/Auth.php @@ -18,7 +18,11 @@ public function process($data) try { $this->access->auth->setUserFromSession(); } catch (\Exception $e) { - $this->access->auth->logout(); + $this->access->auth->logout(true); + + $this->session->set('redirectUrl', $this->request->getUri()); + + return $this->response->redirect($data['appRoute'] . '/auth'); } } @@ -27,7 +31,11 @@ public function process($data) try { $this->access->auth->setUserFromRecaller(); } catch (\Exception $e) { - $this->access->auth->logout(); + $this->access->auth->logout(true); + + $this->session->set('redirectUrl', $this->request->getUri()); + + return $this->response->redirect($data['appRoute'] . '/auth'); } } diff --git a/apps/Core/Packages/Adminltetags/Tags/Activitylogs.php b/apps/Core/Packages/Adminltetags/Tags/Activitylogs.php index 82fbcd5f4..f86537d5c 100644 --- a/apps/Core/Packages/Adminltetags/Tags/Activitylogs.php +++ b/apps/Core/Packages/Adminltetags/Tags/Activitylogs.php @@ -25,10 +25,16 @@ public function getContent(array $params) protected function generateContent() { - if (!isset($this->params['activityLogs'])) { + if (!isset($this->params['activityLogs']['data'])) { throw new \Exception('Error: activityLogs (array) missing'); } + if (count($this->params['activityLogs']['data']) === 0) { + $this->content .= 'No activity logs available for this ID.'; + + return true; + } + if (isset($this->params['activityLogs']['paginationCounters'])) { if ($this->params['activityLogs']['paginationCounters']['first'] === $this->params['activityLogs']['paginationCounters']['current']) { $start = 1; @@ -46,12 +52,8 @@ protected function generateContent() } $this->content .= - '