diff --git a/application/controllers/system/extensions/CLI_Manager.php b/application/controllers/system/extensions/CLI_Manager.php index 110fad9e8..fab511d09 100644 --- a/application/controllers/system/extensions/CLI_Manager.php +++ b/application/controllers/system/extensions/CLI_Manager.php @@ -11,8 +11,8 @@ class CLI_Manager extends CLI_Controller * */ public function __construct() - { - parent::__construct(); + { + parent::__construct(); // Load helpers to upload files $this->load->helper('form'); @@ -30,8 +30,9 @@ class CLI_Manager extends CLI_Controller * @param $filename Url Encoded Pfad zum tgz File der Extension * @param $perform_sql boolean ob die SQL Befehle ausgeführt werden */ - public function uploadExtension($extensionName = null, $filename = null, $perform_sql = true) + public function installExtension($extensionName, $filename, $perform_sql = true) { $this->extensionslib->installExtension($extensionName, urldecode($filename), $perform_sql); } } + diff --git a/application/controllers/system/extensions/Manager.php b/application/controllers/system/extensions/Manager.php index 429c967ae..571b283e8 100644 --- a/application/controllers/system/extensions/Manager.php +++ b/application/controllers/system/extensions/Manager.php @@ -11,8 +11,8 @@ class Manager extends Auth_Controller * */ public function __construct() - { - parent::__construct( + { + parent::__construct( array( 'index' => 'system/extensions:r', 'toggleExtension' => 'system/extensions:rw', @@ -21,11 +21,20 @@ class Manager extends Auth_Controller ) ); - // Load helpers to upload files + // Loads the form helper $this->load->helper('form'); + // Loads WidgetLib + $this->load->library('WidgetLib'); + // Loads the extensions library $this->load->library('ExtensionsLib'); + + $this->loadPhrases( + array( + 'extensions' + ) + ); } /** @@ -50,7 +59,7 @@ class Manager extends Auth_Controller $extension_id = $this->input->post('extension_id'); $enabled = $this->input->post('enabled'); - if ($enabled === 'true') + if ($enabled === true) { $toggleExtension = $this->extensionslib->enableExtension($extension_id); } @@ -59,9 +68,7 @@ class Manager extends Auth_Controller $toggleExtension = $this->extensionslib->disableExtension($extension_id); } - $this->output - ->set_content_type('application/json') - ->set_output(json_encode($toggleExtension)); + $this->outputJsonSuccess($toggleExtension); } /** @@ -69,15 +76,11 @@ class Manager extends Auth_Controller */ public function delExtension() { - $delExtension = false; - $extension_id = $this->input->post('extension_id'); $delExtension = $this->extensionslib->delExtension($extension_id); - $this->output - ->set_content_type('application/json') - ->set_output(json_encode($delExtension)); + $this->outputJsonSuccess($delExtension); } /** @@ -89,11 +92,11 @@ class Manager extends Auth_Controller * @param $filename Url Encoded Pfad zum tgz File der Extension * @param $perform_sql boolean ob die SQL Befehle ausgeführt werden */ - public function uploadExtension($extensionName = null, $filename = null, $perform_sql = true) + public function uploadExtension() { - $perform_sql = $this->input->post('databasechange'); - $perform_sql = isset($perform_sql) ? false : true; + $performSql = $this->input->post('performSql'); - $this->extensionslib->installExtension($extensionName, urldecode($filename), $perform_sql); + $this->extensionslib->installExtension(null, null, $performSql); } } + diff --git a/application/views/system/extensions/manager.php b/application/views/system/extensions/manager.php index ed85e45ea..ea1f0e9ae 100644 --- a/application/views/system/extensions/manager.php +++ b/application/views/system/extensions/manager.php @@ -1,174 +1,58 @@ -load->view('templates/header', array('title' => 'Extensions manager', 'jqueryV1' => true, 'tablesort' => true)); ?> +load->view( + 'templates/FHC-Header', + array( + // Title + 'title' => 'Extensions manager', - + // FHC JS & CSS includes + 'ajaxlib' => true, + 'dialoglib' => true, + 'tabulator' => true, + 'tablewidget' => true, + 'phrases' => array( + 'extensions' + ), + 'customJSs' => array('public/js/ExtensionsManager.js') + ) + ); +?> +
+ - '; - } - elseif (isError($extensions)) - { - echo 'An error occurred while retriving extenions list.'; - } - elseif (hasData($extensions)) - { - ?> +
+ load->view('system/extensions/tableWidget.php'); ?> +
+ +
- List of installed extensions + +
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '; - - foreach ($extensions->retval as $key => $extension) - { - echo sprintf( - $tableRow, - $extension->name, - $extension->description, - $extension->server_kurzbz, - $extension->version, - $extension->license, - $extension->url, - $extension->core_version, - count($extension->dependencies) == 0 ? 'None' : json_encode($extension->dependencies), - $extension->extension_id, - $extension->enabled === true ? 'checked' : '', - $extension->extension_id - ); - } - ?> - - -
NameDescriptionServerVersionLicenceURLMinimum required Core versionDependes on (extensions)Enabled 
%s%s%s%s%s%s%s%s - - - Remove -
- - -
- - - -
- - - +
+
+ + +
+ +
-load->view('templates/footer'); ?> +load->view('templates/FHC-Footer'); ?> diff --git a/application/views/system/extensions/tableWidget.php b/application/views/system/extensions/tableWidget.php new file mode 100644 index 000000000..d2b6fe1aa --- /dev/null +++ b/application/views/system/extensions/tableWidget.php @@ -0,0 +1,95 @@ + ' + SELECT e.extension_id, + e.name, + e.description, + e.server_kurzbz, + e.version, + e.license, + e.url, + e.core_version, + e.dependencies, + e.enabled + FROM system.tbl_extensions e + ORDER BY e.name ASC, + e.server_kurzbz ASC, + e.version ASC + ', + 'tableUniqueId' => 'extensionsListTableWidget', + 'requiredPermissions' => 'system/extensions', + 'datasetRepresentation' => 'tabulator', + 'additionalColumns' => array('Delete'), + 'columnsAliases' => array( + 'Extension ID', + 'Name', + 'Description', + 'Server', + 'Version', + 'License', + 'URL', + 'Core version', + 'Dependencies', + 'Enabled' + ), + 'formatRow' => function($datasetRaw) { + + if ($datasetRaw->{'description'} == null) + { + $datasetRaw->{'description'} = '-'; + } + + if ($datasetRaw->{'server_kurzbz'} == null) + { + $datasetRaw->{'server_kurzbz'} = '-'; + } + + if ($datasetRaw->{'url'} == null) + { + $datasetRaw->{'url'} = '-'; + } + + if ($datasetRaw->{'license'} == null) + { + $datasetRaw->{'license'} = '-'; + } + + return $datasetRaw; + }, + 'datasetRepOptions' => '{ + height: "100%", + layout: "fitColumns", + persistentLayout: true, + persistentSort: true, + persistentFilter: true, + autoResize: false + }', + 'datasetRepFieldsDefs' => '{ + extension_id: {visible: false}, + url: { + formatter: "link" + }, + enabled: { + aligh: "center", + headerSort: false, + editor: true, + formatter: "tickCross", + cellEdited: function(cell) { + if (cell.getValue() != cell.getOldValue()) toggleExtension(cell.getData().extension_id, cell.getValue()); + } + }, + Delete: { + headerSort: false, + formatter: "buttonCross", + width: 100, + align: "center", + cellClick: function(e, cell) { + deleteExtension(cell.getData().extension_id, cell.getRow()); + } + } + }' + ); + + echo $this->widgetlib->widget('TableWidget', $tableWidgetArray); +?> + diff --git a/application/widgets/TableWidget.php b/application/widgets/TableWidget.php index 5a000601f..a0d452747 100644 --- a/application/widgets/TableWidget.php +++ b/application/widgets/TableWidget.php @@ -381,6 +381,19 @@ class TableWidget extends Widget { $rawDatasetRow->{$columnName} = ($columnValue === true ? 'true' : 'false'); } + // if it is an array + elseif (is_array($columnValue)) + { + // Default is an empty string + $rawDatasetRow->{$columnName} = ''; + + // For each element of the array + foreach ($columnValue as $value) + { + $rawDatasetRow->{$columnName} .= $value."\n"; // concatenate each element of the array + } + } + // if it is a date/timestamp elseif (DateTime::createFromFormat('Y-m-d H:i:s', $columnValue) !== false) { $rawDatasetRow->{$columnName} = date(self::DEFAULT_DATE_FORMAT, strtotime($columnValue)); diff --git a/public/js/AjaxLib.js b/public/js/AjaxLib.js index 283061dad..b8fc5a424 100644 --- a/public/js/AjaxLib.js +++ b/public/js/AjaxLib.js @@ -96,16 +96,17 @@ var FHC_AjaxClient = { hasData: function(response) { var hasData = false; - if (FHC_AjaxClient.isSuccess(response)) - { + if (FHC_AjaxClient.isSuccess(response)) + { if ((jQuery.type(response.retval) == "object" && !jQuery.isEmptyObject(response.retval)) || (jQuery.isArray(response.retval) && response.retval.length > 0) || (jQuery.type(response.retval) == "string" && response.retval.trim() != "") - || jQuery.type(response.retval) == "number") + || jQuery.type(response.retval) == "number" + || jQuery.type(response.retval) == "boolean") { hasData = true; } - } + } return hasData; }, diff --git a/public/js/ExtensionsManager.js b/public/js/ExtensionsManager.js new file mode 100644 index 000000000..71e3583f5 --- /dev/null +++ b/public/js/ExtensionsManager.js @@ -0,0 +1,81 @@ +/** + * FH-Complete + * + * @package + * @author + * @copyright Copyright (c) 2016-2021 + * @license GPLv3 + * @link https://fhcomplete.net + * @since Version 1.0.0 + */ + +/** + * Toggle the status of an extension + */ +function toggleExtension(extensionId, enabled) +{ + FHC_AjaxClient.ajaxCallPost( + "system/extensions/Manager/toggleExtension", + { + extension_id: extensionId, + enabled: enabled + }, + { + successCallback: function(data, textStatus, jqXHR) { + if (FHC_AjaxClient.hasData(data) && FHC_AjaxClient.getData(data) === true) + { + FHC_DialogLib.alertSuccess(FHC_PhrasesLib.t("extensions", "changeSuccess")); + } + else + { + FHC_DialogLib.alertError(FHC_PhrasesLib.t("extensions", "changeError")); + } + }, + errorCallback: function(data) { + FHC_DialogLib.alertError(FHC_PhrasesLib.t("extensions", "changeError")); + } + } + ); +} + +/** + * Delete an extension + * cellRow: tabulator row reference + */ +function deleteExtension(extensionId, cellRow) +{ + FHC_AjaxClient.ajaxCallPost( + "system/extensions/Manager/delExtension", + { + extension_id: extensionId + }, + { + successCallback: function(data, textStatus, jqXHR) { + if (FHC_AjaxClient.hasData(data) && FHC_AjaxClient.getData(data) === true) + { + cellRow.delete(); // delete the row from the tabulator + FHC_DialogLib.alertSuccess(FHC_PhrasesLib.t("extensions", "changeSuccess")); + } + else + { + FHC_DialogLib.alertError(FHC_PhrasesLib.t("extensions", "changeError")); + } + }, + errorCallback: function() { + FHC_DialogLib.alertError(FHC_PhrasesLib.t("extensions", "changeError")); + } + } + ); +} + +/** + * When JQuery is up + */ +$(document).ready(function() { + + $("#uploadExtension").click(function() { + $("form").submit(); + }); + +}); + diff --git a/public/js/TableWidget.js b/public/js/TableWidget.js index 6df20066e..6bfc8b610 100644 --- a/public/js/TableWidget.js +++ b/public/js/TableWidget.js @@ -896,3 +896,4 @@ $(document).ready(function() { FHC_TableWidget.display(); }); + diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 7cd0419ae..ec951a3b2 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -25,7 +25,6 @@ //flag for at least one new phrase $new = false; - $phrases = array( //******************* CORE/global array( @@ -12472,6 +12471,106 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'extensions', + 'phrase' => 'title', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Extensions manager', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Extensions manager', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'extensions', + 'phrase' => 'uploadExtension', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Upload extension', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Upload extension', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'extensions', + 'phrase' => 'performSql', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Do not perform SQL', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Do not perform SQL', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'extensions', + 'phrase' => 'changeSuccess', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'The extension have been correctly changed', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'The extension have been correctly changed', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'extensions', + 'phrase' => 'changeError', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'An error occurred while changing the extension', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'An error occurred while changing the extension', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), ); @@ -12594,5 +12693,5 @@ foreach ($phrases as $phrase) } } -if(!$new) - echo 'Keine neuen Phrasen
'; +if (!$new) echo 'Keine neuen Phrasen
'; +