From 231d8aa9844a013231c7edda0865831c59163a0c Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Fri, 24 Aug 2018 23:46:41 +0200 Subject: [PATCH] Added the option to add custom tabs to the edit view of any admin view --- README.md | 14 +- admin/README.txt | 14 +- admin/access.xml | 21 + admin/assets/css/admin_custom_tabs.css | 14 + admin/assets/css/admins_custom_tabs.css | 13 + admin/controller.php | 1 + admin/controllers/admin_custom_tabs.php | 321 +++++++ admin/controllers/admins_custom_tabs.php | 43 + admin/helpers/compiler/a_Get.php | 82 +- admin/helpers/compiler/e_Interpretation.php | 65 +- .../en-GB/en-GB.com_componentbuilder.ini | 87 +- .../en-GB/en-GB.com_componentbuilder.sys.ini | 20 + admin/layouts/admin_custom_tabs/index.html | 1 + .../layouts/admin_custom_tabs/publishing.php | 43 + .../layouts/admin_custom_tabs/publlshing.php | 45 + .../layouts/admin_custom_tabs/tabs_above.php | 26 + .../admin_custom_tabs/tabs_fullwidth.php | 33 + .../layouts/admin_view/settings_fullwidth.php | 1 + admin/models/admin_custom_tabs.php | 864 ++++++++++++++++++ admin/models/admin_view.php | 288 +++--- admin/models/admin_views.php | 96 +- admin/models/admins_custom_tabs.php | 237 +++++ admin/models/ajax.php | 1 + admin/models/componentbuilder.php | 3 + admin/models/fields/viewtabs.php | 68 +- admin/models/forms/admin_custom_tabs.js | 11 + admin/models/forms/admin_custom_tabs.xml | 203 ++++ admin/models/forms/admin_view.js | 2 + admin/models/forms/admin_view.xml | 640 ++++++------- admin/models/import_joomla_components.php | 11 +- admin/models/joomla_components.php | 5 +- admin/sql/install.mysql.utf8.sql | 62 +- admin/sql/uninstall.mysql.utf8.sql | 1 + admin/sql/updates/mysql/2.8.9.sql | 25 + admin/tables/admin_custom_tabs.php | 321 +++++++ admin/views/admin_custom_tabs/submitbutton.js | 35 + admin/views/admin_custom_tabs/tmpl/edit.php | 107 +++ admin/views/admin_custom_tabs/tmpl/index.html | 1 + admin/views/admin_custom_tabs/view.html.php | 193 ++++ admin/views/admin_views/tmpl/default_body.php | 7 +- admin/views/admin_views/view.html.php | 116 +-- admin/views/admins_custom_tabs/index.html | 1 + .../views/admins_custom_tabs/tmpl/default.php | 85 ++ .../tmpl/default_batch_body.php | 18 + .../tmpl/default_batch_footer.php | 23 + .../admins_custom_tabs/tmpl/default_body.php | 94 ++ .../admins_custom_tabs/tmpl/default_foot.php | 18 + .../admins_custom_tabs/tmpl/default_head.php | 47 + .../tmpl/default_toolbar.php | 45 + .../views/admins_custom_tabs/tmpl/index.html | 1 + admin/views/admins_custom_tabs/view.html.php | 224 +++++ componentbuilder.xml | 6 +- componentbuilder_update_server.xml | 25 +- script.php | 137 ++- 54 files changed, 4215 insertions(+), 650 deletions(-) create mode 100644 admin/assets/css/admin_custom_tabs.css create mode 100644 admin/assets/css/admins_custom_tabs.css create mode 100644 admin/controllers/admin_custom_tabs.php create mode 100644 admin/controllers/admins_custom_tabs.php create mode 100644 admin/layouts/admin_custom_tabs/index.html create mode 100644 admin/layouts/admin_custom_tabs/publishing.php create mode 100644 admin/layouts/admin_custom_tabs/publlshing.php create mode 100644 admin/layouts/admin_custom_tabs/tabs_above.php create mode 100644 admin/layouts/admin_custom_tabs/tabs_fullwidth.php create mode 100644 admin/models/admin_custom_tabs.php create mode 100644 admin/models/admins_custom_tabs.php create mode 100644 admin/models/forms/admin_custom_tabs.js create mode 100644 admin/models/forms/admin_custom_tabs.xml create mode 100644 admin/sql/updates/mysql/2.8.9.sql create mode 100644 admin/tables/admin_custom_tabs.php create mode 100644 admin/views/admin_custom_tabs/submitbutton.js create mode 100644 admin/views/admin_custom_tabs/tmpl/edit.php create mode 100644 admin/views/admin_custom_tabs/tmpl/index.html create mode 100644 admin/views/admin_custom_tabs/view.html.php create mode 100644 admin/views/admins_custom_tabs/index.html create mode 100644 admin/views/admins_custom_tabs/tmpl/default.php create mode 100644 admin/views/admins_custom_tabs/tmpl/default_batch_body.php create mode 100644 admin/views/admins_custom_tabs/tmpl/default_batch_footer.php create mode 100644 admin/views/admins_custom_tabs/tmpl/default_body.php create mode 100644 admin/views/admins_custom_tabs/tmpl/default_foot.php create mode 100644 admin/views/admins_custom_tabs/tmpl/default_head.php create mode 100644 admin/views/admins_custom_tabs/tmpl/default_toolbar.php create mode 100644 admin/views/admins_custom_tabs/tmpl/index.html create mode 100644 admin/views/admins_custom_tabs/view.html.php diff --git a/README.md b/README.md index 25f536164..5e53b22c0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.8.9) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.8.10) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -125,14 +125,14 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 23rd August, 2018 -+ *Version*: 2.8.9 ++ *Last Build*: 24th August, 2018 ++ *Version*: 2.8.10 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **189114** -+ *Field count*: **1064** -+ *File count*: **1244** -+ *Folder count*: **197** ++ *Line count*: **192673** ++ *Field count*: **1081** ++ *File count*: **1273** ++ *Folder count*: **201** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/README.txt b/admin/README.txt index 25f536164..5e53b22c0 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.8.9) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.8.10) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -125,14 +125,14 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 23rd August, 2018 -+ *Version*: 2.8.9 ++ *Last Build*: 24th August, 2018 ++ *Version*: 2.8.10 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **189114** -+ *Field count*: **1064** -+ *File count*: **1244** -+ *Folder count*: **197** ++ *Line count*: **192673** ++ *Field count*: **1081** ++ *File count*: **1273** ++ *Folder count*: **201** > This **component** was build with a Joomla [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/access.xml b/admin/access.xml index 244ad0ae8..bf8e8090a 100644 --- a/admin/access.xml +++ b/admin/access.xml @@ -30,6 +30,16 @@ + + + + + + + + + + @@ -582,6 +592,17 @@ +
+ + + + + + + + + +
diff --git a/admin/assets/css/admin_custom_tabs.css b/admin/assets/css/admin_custom_tabs.css new file mode 100644 index 000000000..98f677768 --- /dev/null +++ b/admin/assets/css/admin_custom_tabs.css @@ -0,0 +1,14 @@ +/** + * @package Joomla.Component.Builder + * + * @created 30th April, 2015 + * @author Llewellyn van der Merwe + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +/* CSS Document */ + + +.tab_html { width: 1027px; height: 338px; } diff --git a/admin/assets/css/admins_custom_tabs.css b/admin/assets/css/admins_custom_tabs.css new file mode 100644 index 000000000..e7aab2271 --- /dev/null +++ b/admin/assets/css/admins_custom_tabs.css @@ -0,0 +1,13 @@ +/** + * @package Joomla.Component.Builder + * + * @created 30th April, 2015 + * @author Llewellyn van der Merwe + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +/* CSS Document */ + + diff --git a/admin/controller.php b/admin/controller.php index 772c525e1..90c05d5cf 100644 --- a/admin/controller.php +++ b/admin/controller.php @@ -110,6 +110,7 @@ class ComponentbuilderController extends JControllerLegacy 'admin_fields' => 'admins_fields', 'admin_fields_conditions' => 'admins_fields_conditions', 'admin_fields_relations' => 'admins_fields_relations', + 'admin_custom_tabs' => 'admins_custom_tabs', 'component_admin_views' => 'components_admin_views', 'component_site_views' => 'components_site_views', 'component_custom_admin_views' => 'components_custom_admin_views', diff --git a/admin/controllers/admin_custom_tabs.php b/admin/controllers/admin_custom_tabs.php new file mode 100644 index 000000000..7b35a64fa --- /dev/null +++ b/admin/controllers/admin_custom_tabs.php @@ -0,0 +1,321 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +/** + * Admin_custom_tabs Controller + */ +class ComponentbuilderControllerAdmin_custom_tabs extends JControllerForm +{ + /** + * Current or most recently performed task. + * + * @var string + * @since 12.2 + * @note Replaces _task. + */ + protected $task; + + /** + * Class constructor. + * + * @param array $config A named array of configuration variables. + * + * @since 1.6 + */ + public function __construct($config = array()) + { + $this->view_list = 'Admins_custom_tabs'; // safeguard for setting the return view listing to the main view. + parent::__construct($config); + } + + /** + * Method override to check if you can add a new record. + * + * @param array $data An array of input data. + * + * @return boolean + * + * @since 1.6 + */ + protected function allowAdd($data = array()) + { + // Get user object. + $user = JFactory::getUser(); + // Access check. + $access = $user->authorise('admin_custom_tabs.access', 'com_componentbuilder'); + if (!$access) + { + return false; + } + + // In the absense of better information, revert to the component permissions. + return $user->authorise('admin_custom_tabs.create', $this->option); + } + + /** + * Method override to check if you can edit an existing record. + * + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. + * + * @return boolean + * + * @since 1.6 + */ + protected function allowEdit($data = array(), $key = 'id') + { + // get user object. + $user = JFactory::getUser(); + // get record id. + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + + + // Access check. + $access = ($user->authorise('admin_custom_tabs.access', 'com_componentbuilder.admin_custom_tabs.' . (int) $recordId) && $user->authorise('admin_custom_tabs.access', 'com_componentbuilder')); + if (!$access) + { + return false; + } + + if ($recordId) + { + // The record has been set. Check the record permissions. + $permission = $user->authorise('admin_custom_tabs.edit', 'com_componentbuilder.admin_custom_tabs.' . (int) $recordId); + if (!$permission) + { + if ($user->authorise('admin_custom_tabs.edit.own', 'com_componentbuilder.admin_custom_tabs.' . $recordId)) + { + // Now test the owner is the user. + $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; + if (empty($ownerId)) + { + // Need to do a lookup from the model. + $record = $this->getModel()->getItem($recordId); + + if (empty($record)) + { + return false; + } + $ownerId = $record->created_by; + } + + // If the owner matches 'me' then allow. + if ($ownerId == $user->id) + { + if ($user->authorise('admin_custom_tabs.edit.own', 'com_componentbuilder')) + { + return true; + } + } + } + return false; + } + } + // Since there is no permission, revert to the component permissions. + return $user->authorise('admin_custom_tabs.edit', $this->option); + } + + /** + * Gets the URL arguments to append to an item redirect. + * + * @param integer $recordId The primary key id for the item. + * @param string $urlVar The name of the URL variable for the id. + * + * @return string The arguments to append to the redirect URL. + * + * @since 1.6 + */ + protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') + { + // get the referral options (old method use return instead see parent) + $ref = $this->input->get('ref', 0, 'string'); + $refid = $this->input->get('refid', 0, 'int'); + + // get redirect info. + $append = parent::getRedirectToItemAppend($recordId, $urlVar); + + // set the referral options + if ($refid && $ref) + { + $append = '&ref=' . (string)$ref . '&refid='. (int)$refid . $append; + } + elseif ($ref) + { + $append = '&ref='. (string)$ref . $append; + } + + return $append; + } + + /** + * Method to run batch operations. + * + * @param object $model The model. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 2.5 + */ + public function batch($model = null) + { + JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + // Set the model + $model = $this->getModel('Admin_custom_tabs', '', array()); + + // Preset the redirect + $this->setRedirect(JRoute::_('index.php?option=com_componentbuilder&view=admins_custom_tabs' . $this->getRedirectToListAppend(), false)); + + return parent::batch($model); + } + + /** + * Method to cancel an edit. + * + * @param string $key The name of the primary key of the URL variable. + * + * @return boolean True if access level checks pass, false otherwise. + * + * @since 12.2 + */ + public function cancel($key = null) + { + // get the referral options + $this->ref = $this->input->get('ref', 0, 'word'); + $this->refid = $this->input->get('refid', 0, 'int'); + + // Check if there is a return value + $return = $this->input->get('return', null, 'base64'); + + $cancel = parent::cancel($key); + + if (!is_null($return) && JUri::isInternal(base64_decode($return))) + { + $redirect = base64_decode($return); + + // Redirect to the return value. + $this->setRedirect( + JRoute::_( + $redirect, false + ) + ); + } + elseif ($this->refid && $this->ref) + { + $redirect = '&view=' . (string)$this->ref . '&layout=edit&id=' . (int)$this->refid; + + // Redirect to the item screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + elseif ($this->ref) + { + $redirect = '&view='.(string)$this->ref; + + // Redirect to the list screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + return $cancel; + } + + /** + * Method to save a record. + * + * @param string $key The name of the primary key of the URL variable. + * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). + * + * @return boolean True if successful, false otherwise. + * + * @since 12.2 + */ + public function save($key = null, $urlVar = null) + { + // get the referral options + $this->ref = $this->input->get('ref', 0, 'word'); + $this->refid = $this->input->get('refid', 0, 'int'); + + // Check if there is a return value + $return = $this->input->get('return', null, 'base64'); + $canReturn = (!is_null($return) && JUri::isInternal(base64_decode($return))); + + if ($this->ref || $this->refid || $canReturn) + { + // to make sure the item is checkedin on redirect + $this->task = 'save'; + } + + $saved = parent::save($key, $urlVar); + + // This is not needed since parent save already does this + // Due to the ref and refid implementation we need to add this + if ($canReturn) + { + $redirect = base64_decode($return); + + // Redirect to the return value. + $this->setRedirect( + JRoute::_( + $redirect, false + ) + ); + } + elseif ($this->refid && $this->ref) + { + $redirect = '&view=' . (string)$this->ref . '&layout=edit&id=' . (int)$this->refid; + + // Redirect to the item screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + elseif ($this->ref) + { + $redirect = '&view=' . (string)$this->ref; + + // Redirect to the list screen. + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . $redirect, false + ) + ); + } + return $saved; + } + + /** + * Function that allows child controller access to model data + * after the data has been saved. + * + * @param JModel &$model The data model object. + * @param array $validData The validated data. + * + * @return void + * + * @since 11.1 + */ + protected function postSaveHook(JModelLegacy $model, $validData = array()) + { + return; + } + +} diff --git a/admin/controllers/admins_custom_tabs.php b/admin/controllers/admins_custom_tabs.php new file mode 100644 index 000000000..fbc7a9fa2 --- /dev/null +++ b/admin/controllers/admins_custom_tabs.php @@ -0,0 +1,43 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +/** + * Admins_custom_tabs Controller + */ +class ComponentbuilderControllerAdmins_custom_tabs extends JControllerAdmin +{ + /** + * The prefix to use with controller messages. + * + * @var string + * @since 1.6 + */ + protected $text_prefix = 'COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS'; + + /** + * Method to get a model object, loading it if required. + * + * @param string $name The model name. Optional. + * @param string $prefix The class prefix. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return JModelLegacy The model. + * + * @since 1.6 + */ + public function getModel($name = 'Admin_custom_tabs', $prefix = 'ComponentbuilderModel', $config = array('ignore_request' => true)) + { + return parent::getModel($name, $prefix, $config); + } +} diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 9a4853e2b..6ceccddbf 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -541,6 +541,13 @@ class Get */ public $linkedAdminViews = array(); + /** + * The custom admin view tabs + * + * @var array + */ + public $customTabs = array(); + /** * The Add Ajax Switch * @@ -1455,13 +1462,15 @@ class Get 'b.id', 'c.addconditions', 'c.id', - 'r.addrelations' + 'r.addrelations', + 't.tabs' ), array( 'addfields', 'addfields_id', 'addconditions', 'addconditions_id', - 'addrelations' + 'addrelations', + 'customtabs' ) ) ); @@ -1469,6 +1478,7 @@ class Get $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields', 'b') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('b.admin_view') . ')'); $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields_conditions', 'c') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('c.admin_view') . ')'); $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields_relations', 'r') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('r.admin_view') . ')'); + $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_custom_tabs', 't') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('t.admin_view') . ')'); $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); // Reset the query using our newly populated query object. @@ -1533,7 +1543,73 @@ class Get $view->tables = array_values($view->addtables); } unset($view->addtables); - // add the tabs + + // set custom tabs + $this->customTabs[$name_single] = null; + $view->customtabs = (isset($view->customtabs) && ComponentbuilderHelper::checkJson($view->customtabs)) ? json_decode($view->customtabs, true) : null; + if (ComponentbuilderHelper::checkArray($view->customtabs)) + { + // setup custom tabs to global data sets + $this->customTabs[$name_single] = array_map( function ($tab) use($name_single) { + // set the view name + $tab['view'] = $name_single; + // load the dynamic data + $tab['html'] = $this->setDynamicValues($tab['html']); + // set the tab name + $tab['name'] = (isset($tab['name']) && ComponentbuilderHelper::checkString($tab['name'])) ? $tab['name'] : 'Tab'; + // set lang + $tab['lang'] = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($tab['view'], 'U') . '_' . ComponentbuilderHelper::safeString($tab['name'], 'U'); + $this->langContent['both'][$tab['lang']] = trim($tab['name']); + // set code name + $tab['code'] = ComponentbuilderHelper::safeString($tab['name']); + // check if the permissions for the tab should be added + $_tab = ''; + if (isset($tab['permission']) && $tab['permission'] == 1) + { + $_tab = $this->_t(1); + } + // check if the php of the tab is set, if not load it now + if (strpos($tab['html'], 'bootstrap.addTab') === false && strpos($tab['html'], 'bootstrap.endTab') === false) + { + // add the tab + $tmp = PHP_EOL . $_tab . $this->_t(1) . ""; + $tmp .= PHP_EOL . $_tab . $this->_t(2) . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(3) . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(4) . implode(PHP_EOL . $_tab . $this->_t(4), (array) explode(PHP_EOL, trim($tab['html']))); + $tmp .= PHP_EOL . $_tab . $this->_t(3) . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(2) . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(1) . ""; + // update html + $tab['html'] = $tmp; + } + else + { + $tab['html'] = PHP_EOL . $_tab. $this->_t(1) . implode(PHP_EOL . $_tab. $this->_t(1), (array) explode(PHP_EOL, trim($tab['html']))); + } + // add the permissions if needed + if (isset($tab['permission']) && $tab['permission'] == 1) + { + $tmp = PHP_EOL . $this->_t(1) . "canDo->get('" . $tab['view'] . "." . $tab['code'] . ".viewtab')) : ?>"; + $tmp .= $tab['html']; + $tmp .= PHP_EOL . $this->_t(1) . ""; + // update html + $tab['html'] = $tmp; + // set lang for permissions + $tab['lang_permission'] = $tab['lang'] . '_TAB_PERMISSION'; + $tab['lang_permission_desc'] = $tab['lang'] . '_TAB_PERMISSION_DESC'; + $tab['lang_permission_title'] = $this->placeholders[$this->hhh . 'Views' . $this->hhh] . ' View ' . $tab['name'] . ' Tab'; + $this->langContent['both'][$tab['lang_permission']] = $tab['lang_permission_title']; + $this->langContent['both'][$tab['lang_permission_desc']] = 'Allow the users in this group to view ' . $tab['name'] . ' Tab of ' . $this->placeholders[$this->hhh . 'views' . $this->hhh]; + // set the sort key + $tab['sortKey'] = ComponentbuilderHelper::safeString($tab['lang_permission_title']); + } + // return tab + return $tab; + }, array_values($view->customtabs)); + } + unset($view->customtabs); + + // add the local tabs $view->addtabs = (isset($view->addtabs) && ComponentbuilderHelper::checkJson($view->addtabs)) ? json_decode($view->addtabs, true) : null; if (ComponentbuilderHelper::checkArray($view->addtabs)) { diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 291cbb0c0..f943facb0 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -7259,6 +7259,8 @@ class Interpretation extends Fields } } } + // custom tab searching array + $searchTabs = array(); // start tab set $bucket = array(); $leftside = ''; @@ -7270,12 +7272,16 @@ class Interpretation extends Fields ksort($this->tabCounter[$viewName_single]); foreach ($this->tabCounter[$viewName_single] as $tabNr => $tabName) { + // check if we must load a custom tab + $tabWidth = 12; $lrCounter = 0; // set tab lang $tabLangName = $langView . '_' . ComponentbuilderHelper::safeString($tabName, 'U'); // set tab code name $tabCodeName = ComponentbuilderHelper::safeString($tabName); + /// set the values to use in search latter + $searchTabs[$tabCodeName] = $tabNr; // add to lang array if (!isset($this->langContent[$this->lang][$tabLangName])) { @@ -7480,6 +7486,11 @@ class Interpretation extends Fields { $body .= PHP_EOL . PHP_EOL . $this->_t(1) . " '" . $tabCodeName . "')); ?>"; } + // check if custom tab must be added + if (($_customTabHTML = $this->addCustomTabs($searchTabs[$tabCodeName], $viewName_single, 1)) !== false) + { + $body .= $_customTabHTML; + } // if this is a linked view set permissions $closeIT = false; if (isset($linkedViewIdentifier) && ComponentbuilderHelper::checkArray($linkedViewIdentifier) && in_array($tabCodeName, $linkedViewIdentifier)) @@ -7530,10 +7541,15 @@ class Interpretation extends Fields { $body .= PHP_EOL . $this->_t(1) . ""; } + // check if custom tab must be added + if (($_customTabHTML = $this->addCustomTabs($searchTabs[$tabCodeName], $viewName_single, 2)) !== false) + { + $body .= $_customTabHTML; + } // set counter $tabCounter++; } - // add option to load forms loded in via plugins + // add option to load forms loded in via plugins (TODO) we may want to move these tab locations $body .= PHP_EOL . PHP_EOL . $this->_t(1) . "ignore_fieldsets = array('details','metadata','vdmmetadata','accesscontrol'); ?>"; $body .= PHP_EOL . $this->_t(1) . "tab_name = '" . $viewName_single . "Tab'; ?>"; $body .= PHP_EOL . $this->_t(1) . ""; @@ -7698,6 +7714,11 @@ class Interpretation extends Fields $publishingPer[] = "\$this->canDo->get('" . $core_permission . "')"; } } + // check if custom tab must be added + if (($_customTabHTML = $this->addCustomTabs(15, $viewName_single, 1)) !== false) + { + $body .= $_customTabHTML; + } $body .= PHP_EOL . PHP_EOL . $this->_t(1) . ""; // set the default publishing tab $body .= PHP_EOL . $this->_t(1) . ""; @@ -7717,6 +7738,11 @@ class Interpretation extends Fields $body .= PHP_EOL . $this->_t(2) . ""; $body .= PHP_EOL . $this->_t(1) . ""; $body .= PHP_EOL . $this->_t(1) . ""; + // check if custom tab must be added + if (($_customTabHTML = $this->addCustomTabs(15, $viewName_single, 2)) !== false) + { + $body .= $_customTabHTML; + } } // make sure we dont load it to a view with the name component if ($viewName_single != 'component') @@ -7782,6 +7808,32 @@ class Interpretation extends Fields return ''; } + protected function addCustomTabs($nr, $name_single, $target) + { + // check if this view is having custom tabs + if (isset($this->customTabs[$name_single]) && ComponentbuilderHelper::checkArray($this->customTabs[$name_single])) + { + $html = array(); + foreach ($this->customTabs[$name_single] as $customTab) + { + if (ComponentbuilderHelper::checkArray($customTab) && isset($customTab['html'])) + { + if ($customTab['tab'] == $nr && $customTab['position'] == $target + && isset($customTab['html']) && ComponentbuilderHelper::checkString($customTab['html'])) + { + $html[] = $customTab['html']; + } + } + } + // return if found + if (ComponentbuilderHelper::checkArray($html)) + { + return PHP_EOL . implode(PHP_EOL, $html); + } + } + return false; + } + public function setFadeInEfect(&$view) { // check if we should load the fade in affect @@ -15201,6 +15253,17 @@ function vdm_dkim() { // set view name $nameView = ComponentbuilderHelper::safeString($view['settings']->name_single); $nameViews = ComponentbuilderHelper::safeString($view['settings']->name_list); + // add custom tab permissions if found + if (isset($this->customTabs[$nameView]) && ComponentbuilderHelper::checkArray($this->customTabs[$nameView])) + { + foreach ($this->customTabs[$nameView] as $_customTab) + { + if (isset($_customTab['permission']) && $_customTab['permission'] == 1) + { + $this->componentGlobal[$_customTab['sortKey']] = $this->_t(2) . ''; + } + } + } // add the custom permissions to use the buttons of this view $this->addCustomButtonPermissions($view['settings'], $view['settings']->name_single, $nameView); if ($nameView != 'component') diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index 7c00cacf1..bb87da27d 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -16,6 +16,46 @@ COM_COMPONENTBUILDER_ADD_MORE_FIELDS_TO_THIS_ADMIN_VIEW="Add more fields to this COM_COMPONENTBUILDER_ADD_TO_BACKUP_FOLDER_AMP_SALES_SERVER_SMALLIF_SETSMALL="Add to Backup Folder & Sales Server (if set)" COM_COMPONENTBUILDER_ADD_TO_REPOSITORY_FOLDER="Add to Repository Folder" COM_COMPONENTBUILDER_ADD_YOUR_OWN_JCB_PACKAGES_TO_THE_COMMUNITY_A_S_GITHUBA_REPOSITORYBR_WATCH_THIS_A_S_TUTORIALA_TO_SEE_HOW="Add your own JCB packages to the community gitHub repository.
Watch this tutorial to see how!" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS="Admins Custom Tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_ACCESS="Admins Custom Tabs Access" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_ACCESS_DESC="Allows the users in this group to access access admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_BATCH_OPTIONS="Batch process the selected Admins Custom Tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_BATCH_TIP="All changes will be applied to all selected Admins Custom Tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_BATCH_USE="Admins Custom Tabs Batch Use" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_BATCH_USE_DESC="Allows users in this group to use batch copy/update method of batch admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_CREATE="Admins Custom Tabs Create" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_CREATE_DESC="Allows the users in this group to create create admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_DELETE="Admins Custom Tabs Delete" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_DELETE_DESC="Allows the users in this group to delete delete admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT="Admins Custom Tabs Edit" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_BY="Admins Custom Tabs Edit Created By" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_BY_DESC="Allows the users in this group to update the created by of the edit created by admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_DATE="Admins Custom Tabs Edit Created Date" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_DATE_DESC="Allows the users in this group to update the created date of the edit created admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_DESC="Allows the users in this group to edit the admin custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_OWN="Admins Custom Tabs Edit Own" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_OWN_DESC="Allows the users in this group to edit edit own admins custom tabs created by them" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_STATE="Admins Custom Tabs Edit State" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_STATE_DESC="Allows the users in this group to update the state of the admin custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_VERSION="Admins Custom Tabs Edit Version" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_VERSION_DESC="Allows users in this group to edit versions of version admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_ARCHIVED="%s Admins Custom Tabs archived." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_ARCHIVED_1="%s Admin Custom Tabs archived." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_CHECKED_IN_0="No Admin Custom Tabs successfully checked in." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_CHECKED_IN_1="%d Admin Custom Tabs successfully checked in." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_CHECKED_IN_MORE="%d Admins Custom Tabs successfully checked in." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_DELETED="%s Admins Custom Tabs deleted." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_DELETED_1="%s Admin Custom Tabs deleted." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_FEATURED="%s Admins Custom Tabs featured." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_FEATURED_1="%s Admin Custom Tabs featured." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_PUBLISHED="%s Admins Custom Tabs published." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_PUBLISHED_1="%s Admin Custom Tabs published." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_TRASHED="%s Admins Custom Tabs trashed." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_TRASHED_1="%s Admin Custom Tabs trashed." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_UNFEATURED="%s Admins Custom Tabs unfeatured." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_UNFEATURED_1="%s Admin Custom Tabs unfeatured." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_UNPUBLISHED="%s Admins Custom Tabs unpublished." +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_N_ITEMS_UNPUBLISHED_1="%s Admin Custom Tabs unpublished." COM_COMPONENTBUILDER_ADMINS_FIELDS="Admins Fields" COM_COMPONENTBUILDER_ADMINS_FIELDS_ACCESS="Admins Fields Access" COM_COMPONENTBUILDER_ADMINS_FIELDS_ACCESS_DESC="Allows the users in this group to access access admins fields" @@ -137,6 +177,47 @@ COM_COMPONENTBUILDER_ADMINS_FIELDS_RELATIONS_N_ITEMS_UNFEATURED_1="%s Admin Fiel COM_COMPONENTBUILDER_ADMINS_FIELDS_RELATIONS_N_ITEMS_UNPUBLISHED="%s Admins Fields Relations unpublished." COM_COMPONENTBUILDER_ADMINS_FIELDS_RELATIONS_N_ITEMS_UNPUBLISHED_1="%s Admin Fields Relations unpublished." COM_COMPONENTBUILDER_ADMIN_BEHAVIOUR="Admin Behaviour" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS="Admin Custom Tabs" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_ADMIN_VIEW="Admin View" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_ADMIN_VIEW_DESCRIPTION="Select an admin view" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_ADMIN_VIEW_LABEL="View" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_AFTER_SELECTED_TAB="After selected tab" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_BEFORE_SELECTED_TAB="Before selected tab" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_CREATED_BY_DESC="The user that created this Admin Custom Tabs." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_CREATED_BY_LABEL="Created By" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_CREATED_DATE_DESC="The date this Admin Custom Tabs was created." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_CREATED_DATE_LABEL="Created Date" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_EDIT="Editing the Admin Custom Tabs" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_ERROR_UNIQUE_ALIAS="Another Admin Custom Tabs has the same alias." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_HTML_HINT="// Add the tab HTML here. To access php values methodname->value; ?>" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_HTML_LABEL="HTML" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_ID="Id" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_MODIFIED_BY_DESC="The last user that modified this Admin Custom Tabs." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_MODIFIED_BY_LABEL="Modified By" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_MODIFIED_DATE_DESC="The date this Admin Custom Tabs was modified." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_MODIFIED_DATE_LABEL="Modified Date" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_NAME_DESCRIPTION="Enter Name Here" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_NAME_HINT="Name Here" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_NAME_LABEL="Name" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_NAME_MESSAGE="Error! Please add name here." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_NEW="A New Admin Custom Tabs" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_ORDERING_LABEL="Ordering" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_PERMISSION="Permissions" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_PERMISSION_DESCRIPTION="control " +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_PERMISSION_LABEL="Permission" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_POSITION_DESCRIPTION="position of custom tab" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_POSITION_LABEL="Target" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_PUBLISHING="Publishing" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_SAVE_WARNING="Alias already existed so a number was added at the end. You can re-edit the Admin Custom Tabs to customise the alias." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_STATUS="Status" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_TAB="Tab" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_TABS="Tabs" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_TABS_DESCRIPTION="Set your custom tabs here in relation to your other tabs." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_TABS_LABEL="Tabs" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_TAB_DESCRIPTION="Select the correct tab." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_TAB_LABEL="Admin Tabs" +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_VERSION_DESC="A count of the number of times this Admin Custom Tabs has been revised." +COM_COMPONENTBUILDER_ADMIN_CUSTOM_TABS_VERSION_LABEL="Revision" COM_COMPONENTBUILDER_ADMIN_FIELDS="Admin Fields" COM_COMPONENTBUILDER_ADMIN_FIELDS_ABOVE_TABS="Above Tabs" COM_COMPONENTBUILDER_ADMIN_FIELDS_ACCESS="Access" @@ -307,8 +388,8 @@ COM_COMPONENTBUILDER_ADMIN_FIELDS_SORT_DESCRIPTION="Select if the field should b COM_COMPONENTBUILDER_ADMIN_FIELDS_SORT_LABEL="Sortable" COM_COMPONENTBUILDER_ADMIN_FIELDS_STATUS="Status" COM_COMPONENTBUILDER_ADMIN_FIELDS_TAB="Tab" -COM_COMPONENTBUILDER_ADMIN_FIELDS_TAB_DESCRIPTION="Select the tab this field belongs to." -COM_COMPONENTBUILDER_ADMIN_FIELDS_TAB_LABEL="Tab" +COM_COMPONENTBUILDER_ADMIN_FIELDS_TAB_DESCRIPTION="Select the correct tab." +COM_COMPONENTBUILDER_ADMIN_FIELDS_TAB_LABEL="Admin Tabs" COM_COMPONENTBUILDER_ADMIN_FIELDS_TITLE_DESCRIPTION="Select if the field is the title field." COM_COMPONENTBUILDER_ADMIN_FIELDS_TITLE_LABEL="Title" COM_COMPONENTBUILDER_ADMIN_FIELDS_UNDERNEATH_TABS="Underneath Tabs" @@ -718,6 +799,7 @@ COM_COMPONENTBUILDER_ADMIN_VIEW_NOTE_CREATE_EDIT_DISPLAY_DESCRIPTION="
Display of the fields conditions will load here!
" COM_COMPONENTBUILDER_ADMIN_VIEW_NOTE_CREATE_EDIT_NOTICE_DESCRIPTION="
Welcome to the new improved fields and conditions layout.

We had to remove the repeatable fields layouts since Joomla has depreciated it. With this new improved layout we trust your experience will be better then ever before.

You can still watch the tutorials, and though it was made during the time repeatable fields were still being used, the various concepts and layouts still look mostly the same.

" COM_COMPONENTBUILDER_ADMIN_VIEW_NOTE_CREATE_EDIT_NOTICE_LABEL="Fields & Conditions" +COM_COMPONENTBUILDER_ADMIN_VIEW_NOTE_CUSTOM_TABS_NOTE_DESCRIPTION="You can add more custom tabs to this admin view, these tabs are generally used for static HTML content or Ajax generated fields/content. You can not have an admin view with only custom tabs, they can only be used as an add-on, not a stand alone." COM_COMPONENTBUILDER_ADMIN_VIEW_NOTE_LINKED_TO_NOTICE_DESCRIPTION="
Searching the database.
" COM_COMPONENTBUILDER_ADMIN_VIEW_NOTE_LINKED_TO_NOTICE_LABEL="Linked To" COM_COMPONENTBUILDER_ADMIN_VIEW_NOTE_ON_LINKED_VIEWS_DESCRIPTION="You can link other views that has relationship with this view. Please watch this tutorial for more info. " @@ -6601,6 +6683,7 @@ COM_COMPONENTBUILDER_THESE_ARE_THE_SAME_PACKAGES_FOUND_ON_A_S_GITHUBA_AND_CAN_BE COM_COMPONENTBUILDER_THESE_ARE_THE_SAME_PACKAGES_FOUND_ON_A_S_GITHUBA_AND_CAN_BE_IMPORTED_BY_SIMPLY_MAKING_A_SELECTION_AND_THEN_CLICKING_THE_BGET_PACKAGEB_BUTTONBR_SOME_OF_THESE_PACKAGES_WOULD_REQUIRE_A_KEY_SINCE_THEY_ARE_NOT_FREE_A_S_GET_A_KEY_TODAYA="These are the same packages found on gitHub and can be imported by simply making a selection and then clicking the [Get Package] button.
Some of these packages would require a key, since they are not free. Get a key today!." COM_COMPONENTBUILDER_THESE_OPTIONS_ARE_NOT_AVAILABLE_TO_THE_FIELD_IF_BNONE_DBB_OPTION_IS_SELECTED="These options are not available to the field if None DB option is selected." COM_COMPONENTBUILDER_THESE_OPTIONS_ARE_ONLY_AVAILABLE_TO_THE_FIELD_IF_BSHOW_IN_LIST_VIEWB_OPTION_IS_SELECTED="These options are only available to the field if Show in list view option is selected." +COM_COMPONENTBUILDER_THE_ADMIN_CUSTOM_TABS="The admin custom tabs" COM_COMPONENTBUILDER_THE_ADMIN_FIELDS="The admin fields" COM_COMPONENTBUILDER_THE_ADMIN_FIELDS_CONDITIONS="The admin fields conditions" COM_COMPONENTBUILDER_THE_ADMIN_FIELDS_RELATIONS="The admin fields relations" diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini b/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini index 6ae4340a2..cd8f7fc00 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.sys.ini @@ -1,4 +1,24 @@ COM_COMPONENTBUILDER="Component Builder" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_ACCESS="Admins Custom Tabs Access" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_ACCESS_DESC="Allows the users in this group to access access admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_BATCH_USE="Admins Custom Tabs Batch Use" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_BATCH_USE_DESC="Allows users in this group to use batch copy/update method of batch admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_CREATE="Admins Custom Tabs Create" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_CREATE_DESC="Allows the users in this group to create create admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_DELETE="Admins Custom Tabs Delete" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_DELETE_DESC="Allows the users in this group to delete delete admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT="Admins Custom Tabs Edit" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_BY="Admins Custom Tabs Edit Created By" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_BY_DESC="Allows the users in this group to update the created by of the edit created by admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_DATE="Admins Custom Tabs Edit Created Date" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_CREATED_DATE_DESC="Allows the users in this group to update the created date of the edit created admins custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_DESC="Allows the users in this group to edit the admin custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_OWN="Admins Custom Tabs Edit Own" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_OWN_DESC="Allows the users in this group to edit edit own admins custom tabs created by them" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_STATE="Admins Custom Tabs Edit State" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_STATE_DESC="Allows the users in this group to update the state of the admin custom tabs" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_VERSION="Admins Custom Tabs Edit Version" +COM_COMPONENTBUILDER_ADMINS_CUSTOM_TABS_EDIT_VERSION_DESC="Allows users in this group to edit versions of version admins custom tabs" COM_COMPONENTBUILDER_ADMINS_FIELDS_ACCESS="Admins Fields Access" COM_COMPONENTBUILDER_ADMINS_FIELDS_ACCESS_DESC="Allows the users in this group to access access admins fields" COM_COMPONENTBUILDER_ADMINS_FIELDS_BATCH_USE="Admins Fields Batch Use" diff --git a/admin/layouts/admin_custom_tabs/index.html b/admin/layouts/admin_custom_tabs/index.html new file mode 100644 index 000000000..fa6d84e80 --- /dev/null +++ b/admin/layouts/admin_custom_tabs/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/admin/layouts/admin_custom_tabs/publishing.php b/admin/layouts/admin_custom_tabs/publishing.php new file mode 100644 index 000000000..ea58156d1 --- /dev/null +++ b/admin/layouts/admin_custom_tabs/publishing.php @@ -0,0 +1,43 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +$app = JFactory::getApplication(); +$form = $displayData->getForm(); + +$fields = $displayData->get('fields') ?: array( + 'created', + 'created_by', + 'modified', + 'modified_by' +); + +$hiddenFields = $displayData->get('hidden_fields') ?: array(); + +foreach ($fields as $field) +{ + $field = is_array($field) ? $field : array($field); + foreach ($field as $f) + { + if ($form->getField($f)) + { + if (in_array($f, $hiddenFields)) + { + $form->setFieldAttribute($f, 'type', 'hidden'); + } + + echo $form->renderField($f); + break; + } + } +} diff --git a/admin/layouts/admin_custom_tabs/publlshing.php b/admin/layouts/admin_custom_tabs/publlshing.php new file mode 100644 index 000000000..7dfa73168 --- /dev/null +++ b/admin/layouts/admin_custom_tabs/publlshing.php @@ -0,0 +1,45 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +$app = JFactory::getApplication(); +$form = $displayData->getForm(); + +$fields = $displayData->get('fields') ?: array( + 'published', + 'ordering', + 'access', + 'version', + 'hits', + 'id' +); + +$hiddenFields = $displayData->get('hidden_fields') ?: array(); + +foreach ($fields as $field) +{ + $field = is_array($field) ? $field : array($field); + foreach ($field as $f) + { + if ($form->getField($f)) + { + if (in_array($f, $hiddenFields)) + { + $form->setFieldAttribute($f, 'type', 'hidden'); + } + + echo $form->renderField($f); + break; + } + } +} diff --git a/admin/layouts/admin_custom_tabs/tabs_above.php b/admin/layouts/admin_custom_tabs/tabs_above.php new file mode 100644 index 000000000..fbbf44543 --- /dev/null +++ b/admin/layouts/admin_custom_tabs/tabs_above.php @@ -0,0 +1,26 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +$form = $displayData->getForm(); + +$fields = array( + 'admin_view' +); + +?> +
+ renderField($field); + } ?> +
diff --git a/admin/layouts/admin_custom_tabs/tabs_fullwidth.php b/admin/layouts/admin_custom_tabs/tabs_fullwidth.php new file mode 100644 index 000000000..46a16983d --- /dev/null +++ b/admin/layouts/admin_custom_tabs/tabs_fullwidth.php @@ -0,0 +1,33 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +$form = $displayData->getForm(); + +$fields = $displayData->get('fields') ?: array( + 'tabs' +); + +?> +
+ +
+
+ getLabel($field); ?> +
+
+ getInput($field); ?> +
+
+ +
diff --git a/admin/layouts/admin_view/settings_fullwidth.php b/admin/layouts/admin_view/settings_fullwidth.php index 0b8329080..72bafba04 100644 --- a/admin/layouts/admin_view/settings_fullwidth.php +++ b/admin/layouts/admin_view/settings_fullwidth.php @@ -19,6 +19,7 @@ $fields = $displayData->get('fields') ?: array( 'addpermissions', 'note_on_tabs', 'addtabs', + 'note_custom_tabs_note', 'note_on_linked_views', 'addlinked_views' ); diff --git a/admin/models/admin_custom_tabs.php b/admin/models/admin_custom_tabs.php new file mode 100644 index 000000000..463feb082 --- /dev/null +++ b/admin/models/admin_custom_tabs.php @@ -0,0 +1,864 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +use Joomla\Registry\Registry; + +/** + * Componentbuilder Admin_custom_tabs Model + */ +class ComponentbuilderModelAdmin_custom_tabs extends JModelAdmin +{ + /** + * @var string The prefix to use with controller messages. + * @since 1.6 + */ + protected $text_prefix = 'COM_COMPONENTBUILDER'; + + /** + * The type alias for this content type. + * + * @var string + * @since 3.2 + */ + public $typeAlias = 'com_componentbuilder.admin_custom_tabs'; + + /** + * Returns a Table object, always creating it + * + * @param type $type The table type to instantiate + * @param string $prefix A prefix for the table class name. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return JTable A database object + * + * @since 1.6 + */ + public function getTable($type = 'admin_custom_tabs', $prefix = 'ComponentbuilderTable', $config = array()) + { + // add table path for when model gets used from other component + $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_componentbuilder/tables'); + // get instance of the table + return JTable::getInstance($type, $prefix, $config); + } + + /** + * Method to get a single record. + * + * @param integer $pk The id of the primary key. + * + * @return mixed Object on success, false on failure. + * + * @since 1.6 + */ + public function getItem($pk = null) + { + if ($item = parent::getItem($pk)) + { + if (!empty($item->params) && !is_array($item->params)) + { + // Convert the params field to an array. + $registry = new Registry; + $registry->loadString($item->params); + $item->params = $registry->toArray(); + } + + if (!empty($item->metadata)) + { + // Convert the metadata field to an array. + $registry = new Registry; + $registry->loadString($item->metadata); + $item->metadata = $registry->toArray(); + } + + if (!empty($item->tabs)) + { + // Convert the tabs field to an array. + $tabs = new Registry; + $tabs->loadString($item->tabs); + $item->tabs = $tabs->toArray(); + } + + if (!empty($item->id)) + { + $item->tags = new JHelperTags; + $item->tags->getTagIds($item->id, 'com_componentbuilder.admin_custom_tabs'); + } + } + + return $item; + } + + /** + * Method to get the record form. + * + * @param array $data Data for the form. + * @param boolean $loadData True if the form is to load its own data (default case), false if not. + * @param array $options Optional array of options for the form creation. + * + * @return mixed A JForm object on success, false on failure + * + * @since 1.6 + */ + public function getForm($data = array(), $loadData = true, $options = array('control' => 'jform')) + { + // set load data option + $options['load_data'] = $loadData; + // Get the form. + $form = $this->loadForm('com_componentbuilder.admin_custom_tabs', 'admin_custom_tabs', $options); + + if (empty($form)) + { + return false; + } + + $jinput = JFactory::getApplication()->input; + + // The front end calls this model and uses a_id to avoid id clashes so we need to check for that first. + if ($jinput->get('a_id')) + { + $id = $jinput->get('a_id', 0, 'INT'); + } + // The back end uses id so we use that the rest of the time and set it to 0 by default. + else + { + $id = $jinput->get('id', 0, 'INT'); + } + + $user = JFactory::getUser(); + + // Check for existing item. + // Modify the form based on Edit State access controls. + if ($id != 0 && (!$user->authorise('admin_custom_tabs.edit.state', 'com_componentbuilder.admin_custom_tabs.' . (int) $id)) + || ($id == 0 && !$user->authorise('admin_custom_tabs.edit.state', 'com_componentbuilder'))) + { + // Disable fields for display. + $form->setFieldAttribute('ordering', 'disabled', 'true'); + $form->setFieldAttribute('published', 'disabled', 'true'); + // Disable fields while saving. + $form->setFieldAttribute('ordering', 'filter', 'unset'); + $form->setFieldAttribute('published', 'filter', 'unset'); + } + // If this is a new item insure the greated by is set. + if (0 == $id) + { + // Set the created_by to this user + $form->setValue('created_by', null, $user->id); + } + // Modify the form based on Edit Creaded By access controls. + if ($id != 0 && (!$user->authorise('admin_custom_tabs.edit.created_by', 'com_componentbuilder.admin_custom_tabs.' . (int) $id)) + || ($id == 0 && !$user->authorise('admin_custom_tabs.edit.created_by', 'com_componentbuilder'))) + { + // Disable fields for display. + $form->setFieldAttribute('created_by', 'disabled', 'true'); + // Disable fields for display. + $form->setFieldAttribute('created_by', 'readonly', 'true'); + // Disable fields while saving. + $form->setFieldAttribute('created_by', 'filter', 'unset'); + } + // Modify the form based on Edit Creaded Date access controls. + if ($id != 0 && (!$user->authorise('admin_custom_tabs.edit.created', 'com_componentbuilder.admin_custom_tabs.' . (int) $id)) + || ($id == 0 && !$user->authorise('admin_custom_tabs.edit.created', 'com_componentbuilder'))) + { + // Disable fields for display. + $form->setFieldAttribute('created', 'disabled', 'true'); + // Disable fields while saving. + $form->setFieldAttribute('created', 'filter', 'unset'); + } + // Only load these values if no id is found + if (0 == $id) + { + // Set redirected view name + $redirectedView = $jinput->get('ref', null, 'STRING'); + // Set field name (or fall back to view name) + $redirectedField = $jinput->get('field', $redirectedView, 'STRING'); + // Set redirected view id + $redirectedId = $jinput->get('refid', 0, 'INT'); + // Set field id (or fall back to redirected view id) + $redirectedValue = $jinput->get('field_id', $redirectedId, 'INT'); + if (0 != $redirectedValue && $redirectedField) + { + // Now set the local-redirected field default value + $form->setValue($redirectedField, null, $redirectedValue); + } + } + return $form; + } + + /** + * Method to get the script that have to be included on the form + * + * @return string script files + */ + public function getScript() + { + return 'administrator/components/com_componentbuilder/models/forms/admin_custom_tabs.js'; + } + + /** + * Method to test whether a record can be deleted. + * + * @param object $record A record object. + * + * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. + * + * @since 1.6 + */ + protected function canDelete($record) + { + if (!empty($record->id)) + { + if ($record->published != -2) + { + return; + } + + $user = JFactory::getUser(); + // The record has been set. Check the record permissions. + return $user->authorise('admin_custom_tabs.delete', 'com_componentbuilder.admin_custom_tabs.' . (int) $record->id); + } + return false; + } + + /** + * Method to test whether a record can have its state edited. + * + * @param object $record A record object. + * + * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. + * + * @since 1.6 + */ + protected function canEditState($record) + { + $user = JFactory::getUser(); + $recordId = (!empty($record->id)) ? $record->id : 0; + + if ($recordId) + { + // The record has been set. Check the record permissions. + $permission = $user->authorise('admin_custom_tabs.edit.state', 'com_componentbuilder.admin_custom_tabs.' . (int) $recordId); + if (!$permission && !is_null($permission)) + { + return false; + } + } + // In the absense of better information, revert to the component permissions. + return $user->authorise('admin_custom_tabs.edit.state', 'com_componentbuilder'); + } + + /** + * Method override to check if you can edit an existing record. + * + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. + * + * @return boolean + * @since 2.5 + */ + protected function allowEdit($data = array(), $key = 'id') + { + // Check specific edit permission then general edit permission. + $user = JFactory::getUser(); + + return $user->authorise('admin_custom_tabs.edit', 'com_componentbuilder.admin_custom_tabs.'. ((int) isset($data[$key]) ? $data[$key] : 0)) or $user->authorise('admin_custom_tabs.edit', 'com_componentbuilder'); + } + + /** + * Prepare and sanitise the table data prior to saving. + * + * @param JTable $table A JTable object. + * + * @return void + * + * @since 1.6 + */ + protected function prepareTable($table) + { + $date = JFactory::getDate(); + $user = JFactory::getUser(); + + if (isset($table->name)) + { + $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES); + } + + if (isset($table->alias) && empty($table->alias)) + { + $table->generateAlias(); + } + + if (empty($table->id)) + { + $table->created = $date->toSql(); + // set the user + if ($table->created_by == 0 || empty($table->created_by)) + { + $table->created_by = $user->id; + } + // Set ordering to the last item if not set + if (empty($table->ordering)) + { + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select('MAX(ordering)') + ->from($db->quoteName('#__componentbuilder_admin_custom_tabs')); + $db->setQuery($query); + $max = $db->loadResult(); + + $table->ordering = $max + 1; + } + } + else + { + $table->modified = $date->toSql(); + $table->modified_by = $user->id; + } + + if (!empty($table->id)) + { + // Increment the items version number. + $table->version++; + } + } + + /** + * Method to get the data that should be injected in the form. + * + * @return mixed The data for the form. + * + * @since 1.6 + */ + protected function loadFormData() + { + // Check the session for previously entered form data. + $data = JFactory::getApplication()->getUserState('com_componentbuilder.edit.admin_custom_tabs.data', array()); + + if (empty($data)) + { + $data = $this->getItem(); + } + + return $data; + } + + /** + * Method to get the unique fields of this table. + * + * @return mixed An array of field names, boolean false if none is set. + * + * @since 3.0 + */ + protected function getUniqeFields() + { + return false; + } + + /** + * Method to delete one or more records. + * + * @param array &$pks An array of record primary keys. + * + * @return boolean True if successful, false if an error occurs. + * + * @since 12.2 + */ + public function delete(&$pks) + { + if (!parent::delete($pks)) + { + return false; + } + + return true; + } + + /** + * Method to change the published state of one or more records. + * + * @param array &$pks A list of the primary keys to change. + * @param integer $value The value of the published state. + * + * @return boolean True on success. + * + * @since 12.2 + */ + public function publish(&$pks, $value = 1) + { + if (!parent::publish($pks, $value)) + { + return false; + } + + return true; + } + + /** + * Method to perform batch operations on an item or a set of items. + * + * @param array $commands An array of commands to perform. + * @param array $pks An array of item ids. + * @param array $contexts An array of item contexts. + * + * @return boolean Returns true on success, false on failure. + * + * @since 12.2 + */ + public function batch($commands, $pks, $contexts) + { + // Sanitize ids. + $pks = array_unique($pks); + JArrayHelper::toInteger($pks); + + // Remove any values of zero. + if (array_search(0, $pks, true)) + { + unset($pks[array_search(0, $pks, true)]); + } + + if (empty($pks)) + { + $this->setError(JText::_('JGLOBAL_NO_ITEM_SELECTED')); + return false; + } + + $done = false; + + // Set some needed variables. + $this->user = JFactory::getUser(); + $this->table = $this->getTable(); + $this->tableClassName = get_class($this->table); + $this->contentType = new JUcmType; + $this->type = $this->contentType->getTypeByTable($this->tableClassName); + $this->canDo = ComponentbuilderHelper::getActions('admin_custom_tabs'); + $this->batchSet = true; + + if (!$this->canDo->get('core.batch')) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); + return false; + } + + if ($this->type == false) + { + $type = new JUcmType; + $this->type = $type->getTypeByAlias($this->typeAlias); + } + + $this->tagsObserver = $this->table->getObserverOfClass('JTableObserverTags'); + + if (!empty($commands['move_copy'])) + { + $cmd = JArrayHelper::getValue($commands, 'move_copy', 'c'); + + if ($cmd == 'c') + { + $result = $this->batchCopy($commands, $pks, $contexts); + + if (is_array($result)) + { + foreach ($result as $old => $new) + { + $contexts[$new] = $contexts[$old]; + } + $pks = array_values($result); + } + else + { + return false; + } + } + elseif ($cmd == 'm' && !$this->batchMove($commands, $pks, $contexts)) + { + return false; + } + + $done = true; + } + + if (!$done) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); + + return false; + } + + // Clear the cache + $this->cleanCache(); + + return true; + } + + /** + * Batch copy items to a new category or current. + * + * @param integer $values The new values. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return mixed An array of new IDs on success, boolean false on failure. + * + * @since 12.2 + */ + protected function batchCopy($values, $pks, $contexts) + { + if (empty($this->batchSet)) + { + // Set some needed variables. + $this->user = JFactory::getUser(); + $this->table = $this->getTable(); + $this->tableClassName = get_class($this->table); + $this->canDo = ComponentbuilderHelper::getActions('admin_custom_tabs'); + } + + if (!$this->canDo->get('admin_custom_tabs.create') && !$this->canDo->get('admin_custom_tabs.batch')) + { + return false; + } + + // get list of uniqe fields + $uniqeFields = $this->getUniqeFields(); + // remove move_copy from array + unset($values['move_copy']); + + // make sure published is set + if (!isset($values['published'])) + { + $values['published'] = 0; + } + elseif (isset($values['published']) && !$this->canDo->get('admin_custom_tabs.edit.state')) + { + $values['published'] = 0; + } + + $newIds = array(); + // Parent exists so let's proceed + while (!empty($pks)) + { + // Pop the first ID off the stack + $pk = array_shift($pks); + + $this->table->reset(); + + // only allow copy if user may edit this item. + if (!$this->user->authorise('admin_custom_tabs.edit', $contexts[$pk])) + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + + // Check that the row actually exists + if (!$this->table->load($pk)) + { + if ($error = $this->table->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + } + + // Only for strings + if (ComponentbuilderHelper::checkString($this->table->admin_view) && !is_numeric($this->table->admin_view)) + { + $this->table->admin_view = $this->generateUniqe('admin_view',$this->table->admin_view); + } + + // insert all set values + if (ComponentbuilderHelper::checkArray($values)) + { + foreach ($values as $key => $value) + { + if (strlen($value) > 0 && isset($this->table->$key)) + { + $this->table->$key = $value; + } + } + } + + // update all uniqe fields + if (ComponentbuilderHelper::checkArray($uniqeFields)) + { + foreach ($uniqeFields as $uniqeField) + { + $this->table->$uniqeField = $this->generateUniqe($uniqeField,$this->table->$uniqeField); + } + } + + // Reset the ID because we are making a copy + $this->table->id = 0; + + // TODO: Deal with ordering? + // $this->table->ordering = 1; + + // Check the row. + if (!$this->table->check()) + { + $this->setError($this->table->getError()); + + return false; + } + + if (!empty($this->type)) + { + $this->createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table); + } + + // Store the row. + if (!$this->table->store()) + { + $this->setError($this->table->getError()); + + return false; + } + + // Get the new item ID + $newId = $this->table->get('id'); + + // Add the new ID to the array + $newIds[$pk] = $newId; + } + + // Clean the cache + $this->cleanCache(); + + return $newIds; + } + + /** + * Batch move items to a new category + * + * @param integer $value The new category ID. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 12.2 + */ + protected function batchMove($values, $pks, $contexts) + { + if (empty($this->batchSet)) + { + // Set some needed variables. + $this->user = JFactory::getUser(); + $this->table = $this->getTable(); + $this->tableClassName = get_class($this->table); + $this->canDo = ComponentbuilderHelper::getActions('admin_custom_tabs'); + } + + if (!$this->canDo->get('admin_custom_tabs.edit') && !$this->canDo->get('admin_custom_tabs.batch')) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); + return false; + } + + // make sure published only updates if user has the permission. + if (isset($values['published']) && !$this->canDo->get('admin_custom_tabs.edit.state')) + { + unset($values['published']); + } + // remove move_copy from array + unset($values['move_copy']); + + // Parent exists so we proceed + foreach ($pks as $pk) + { + if (!$this->user->authorise('admin_custom_tabs.edit', $contexts[$pk])) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); + return false; + } + + // Check that the row actually exists + if (!$this->table->load($pk)) + { + if ($error = $this->table->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + } + + // insert all set values. + if (ComponentbuilderHelper::checkArray($values)) + { + foreach ($values as $key => $value) + { + // Do special action for access. + if ('access' === $key && strlen($value) > 0) + { + $this->table->$key = $value; + } + elseif (strlen($value) > 0 && isset($this->table->$key)) + { + $this->table->$key = $value; + } + } + } + + + // Check the row. + if (!$this->table->check()) + { + $this->setError($this->table->getError()); + + return false; + } + + if (!empty($this->type)) + { + $this->createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table); + } + + // Store the row. + if (!$this->table->store()) + { + $this->setError($this->table->getError()); + + return false; + } + } + + // Clean the cache + $this->cleanCache(); + + return true; + } + + /** + * Method to save the form data. + * + * @param array $data The form data. + * + * @return boolean True on success. + * + * @since 1.6 + */ + public function save($data) + { + $input = JFactory::getApplication()->input; + $filter = JFilterInput::getInstance(); + + // set the metadata to the Item Data + if (isset($data['metadata']) && isset($data['metadata']['author'])) + { + $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); + + $metadata = new JRegistry; + $metadata->loadArray($data['metadata']); + $data['metadata'] = (string) $metadata; + } + + // Set the tabs items to data. + if (isset($data['tabs']) && is_array($data['tabs'])) + { + $tabs = new JRegistry; + $tabs->loadArray($data['tabs']); + $data['tabs'] = (string) $tabs; + } + elseif (!isset($data['tabs'])) + { + // Set the empty tabs to data + $data['tabs'] = ''; + } + + // Set the Params Items to data + if (isset($data['params']) && is_array($data['params'])) + { + $params = new JRegistry; + $params->loadArray($data['params']); + $data['params'] = (string) $params; + } + + // Alter the uniqe field for save as copy + if ($input->get('task') === 'save2copy') + { + // Automatic handling of other uniqe fields + $uniqeFields = $this->getUniqeFields(); + if (ComponentbuilderHelper::checkArray($uniqeFields)) + { + foreach ($uniqeFields as $uniqeField) + { + $data[$uniqeField] = $this->generateUniqe($uniqeField,$data[$uniqeField]); + } + } + } + + if (parent::save($data)) + { + return true; + } + return false; + } + + /** + * Method to generate a uniqe value. + * + * @param string $field name. + * @param string $value data. + * + * @return string New value. + * + * @since 3.0 + */ + protected function generateUniqe($field,$value) + { + + // set field value uniqe + $table = $this->getTable(); + + while ($table->load(array($field => $value))) + { + $value = JString::increment($value); + } + + return $value; + } + + /** + * Method to change the title + * + * @param string $title The title. + * + * @return array Contains the modified title and alias. + * + */ + protected function _generateNewTitle($title) + { + + // Alter the title + $table = $this->getTable(); + + while ($table->load(array('title' => $title))) + { + $title = JString::increment($title); + } + + return $title; + } +} diff --git a/admin/models/admin_view.php b/admin/models/admin_view.php index 59c5a5862..10094cbc3 100644 --- a/admin/models/admin_view.php +++ b/admin/models/admin_view.php @@ -86,6 +86,12 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $item->metadata = $registry->toArray(); } + if (!empty($item->php_import_headers)) + { + // base64 Decode php_import_headers. + $item->php_import_headers = base64_decode($item->php_import_headers); + } + if (!empty($item->html_import_view)) { // base64 Decode html_import_view. @@ -98,10 +104,10 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $item->php_import_save = base64_decode($item->php_import_save); } - if (!empty($item->php_import_headers)) + if (!empty($item->php_getitem)) { - // base64 Decode php_import_headers. - $item->php_import_headers = base64_decode($item->php_import_headers); + // base64 Decode php_getitem. + $item->php_getitem = base64_decode($item->php_getitem); } if (!empty($item->php_getitems)) @@ -116,108 +122,108 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $item->php_getitems_after_all = base64_decode($item->php_getitems_after_all); } - if (!empty($item->css_view)) - { - // base64 Decode css_view. - $item->css_view = base64_decode($item->css_view); - } - if (!empty($item->php_getlistquery)) { // base64 Decode php_getlistquery. $item->php_getlistquery = base64_decode($item->php_getlistquery); } + if (!empty($item->css_view)) + { + // base64 Decode css_view. + $item->css_view = base64_decode($item->css_view); + } + if (!empty($item->php_getform)) { // base64 Decode php_getform. $item->php_getform = base64_decode($item->php_getform); } - if (!empty($item->css_views)) - { - // base64 Decode css_views. - $item->css_views = base64_decode($item->css_views); - } - if (!empty($item->php_before_save)) { // base64 Decode php_before_save. $item->php_before_save = base64_decode($item->php_before_save); } + if (!empty($item->css_views)) + { + // base64 Decode css_views. + $item->css_views = base64_decode($item->css_views); + } + if (!empty($item->php_save)) { // base64 Decode php_save. $item->php_save = base64_decode($item->php_save); } - if (!empty($item->javascript_view_file)) - { - // base64 Decode javascript_view_file. - $item->javascript_view_file = base64_decode($item->javascript_view_file); - } - if (!empty($item->php_postsavehook)) { // base64 Decode php_postsavehook. $item->php_postsavehook = base64_decode($item->php_postsavehook); } + if (!empty($item->javascript_view_file)) + { + // base64 Decode javascript_view_file. + $item->javascript_view_file = base64_decode($item->javascript_view_file); + } + if (!empty($item->php_allowadd)) { // base64 Decode php_allowadd. $item->php_allowadd = base64_decode($item->php_allowadd); } - if (!empty($item->javascript_view_footer)) - { - // base64 Decode javascript_view_footer. - $item->javascript_view_footer = base64_decode($item->javascript_view_footer); - } - if (!empty($item->php_allowedit)) { // base64 Decode php_allowedit. $item->php_allowedit = base64_decode($item->php_allowedit); } + if (!empty($item->javascript_view_footer)) + { + // base64 Decode javascript_view_footer. + $item->javascript_view_footer = base64_decode($item->javascript_view_footer); + } + if (!empty($item->php_batchcopy)) { // base64 Decode php_batchcopy. $item->php_batchcopy = base64_decode($item->php_batchcopy); } - if (!empty($item->javascript_views_file)) - { - // base64 Decode javascript_views_file. - $item->javascript_views_file = base64_decode($item->javascript_views_file); - } - if (!empty($item->php_batchmove)) { // base64 Decode php_batchmove. $item->php_batchmove = base64_decode($item->php_batchmove); } + if (!empty($item->javascript_views_file)) + { + // base64 Decode javascript_views_file. + $item->javascript_views_file = base64_decode($item->javascript_views_file); + } + if (!empty($item->php_before_publish)) { // base64 Decode php_before_publish. $item->php_before_publish = base64_decode($item->php_before_publish); } - if (!empty($item->javascript_views_footer)) - { - // base64 Decode javascript_views_footer. - $item->javascript_views_footer = base64_decode($item->javascript_views_footer); - } - if (!empty($item->php_after_publish)) { // base64 Decode php_after_publish. $item->php_after_publish = base64_decode($item->php_after_publish); } + if (!empty($item->javascript_views_footer)) + { + // base64 Decode javascript_views_footer. + $item->javascript_views_footer = base64_decode($item->javascript_views_footer); + } + if (!empty($item->php_before_delete)) { // base64 Decode php_before_delete. @@ -230,36 +236,36 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $item->php_after_delete = base64_decode($item->php_after_delete); } - if (!empty($item->php_controller)) - { - // base64 Decode php_controller. - $item->php_controller = base64_decode($item->php_controller); - } - if (!empty($item->php_document)) { // base64 Decode php_document. $item->php_document = base64_decode($item->php_document); } + if (!empty($item->php_controller)) + { + // base64 Decode php_controller. + $item->php_controller = base64_decode($item->php_controller); + } + if (!empty($item->php_model)) { // base64 Decode php_model. $item->php_model = base64_decode($item->php_model); } - if (!empty($item->php_controller_list)) - { - // base64 Decode php_controller_list. - $item->php_controller_list = base64_decode($item->php_controller_list); - } - if (!empty($item->sql)) { // base64 Decode sql. $item->sql = base64_decode($item->sql); } + if (!empty($item->php_controller_list)) + { + // base64 Decode php_controller_list. + $item->php_controller_list = base64_decode($item->php_controller_list); + } + if (!empty($item->php_model_list)) { // base64 Decode php_model_list. @@ -272,18 +278,18 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $item->php_import_display = base64_decode($item->php_import_display); } - if (!empty($item->php_ajaxmethod)) - { - // base64 Decode php_ajaxmethod. - $item->php_ajaxmethod = base64_decode($item->php_ajaxmethod); - } - if (!empty($item->php_import)) { // base64 Decode php_import. $item->php_import = base64_decode($item->php_import); } + if (!empty($item->php_ajaxmethod)) + { + // base64 Decode php_ajaxmethod. + $item->php_ajaxmethod = base64_decode($item->php_ajaxmethod); + } + if (!empty($item->php_import_setdata)) { // base64 Decode php_import_setdata. @@ -296,10 +302,12 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $item->php_import_ext = base64_decode($item->php_import_ext); } - if (!empty($item->php_getitem)) + if (!empty($item->addtables)) { - // base64 Decode php_getitem. - $item->php_getitem = base64_decode($item->php_getitem); + // Convert the addtables field to an array. + $addtables = new Registry; + $addtables->loadString($item->addtables); + $item->addtables = $addtables->toArray(); } if (!empty($item->addpermissions)) @@ -326,14 +334,6 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $item->addlinked_views = $addlinked_views->toArray(); } - if (!empty($item->addtables)) - { - // Convert the addtables field to an array. - $addtables = new Registry; - $addtables->loadString($item->addtables); - $item->addtables = $addtables->toArray(); - } - if (!empty($item->alias_builder)) { // Convert the alias_builder field to an array. @@ -1220,6 +1220,19 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $data['system_name'] = $data['name_single']; } + // Set the addtables items to data. + if (isset($data['addtables']) && is_array($data['addtables'])) + { + $addtables = new JRegistry; + $addtables->loadArray($data['addtables']); + $data['addtables'] = (string) $addtables; + } + elseif (!isset($data['addtables'])) + { + // Set the empty addtables to data + $data['addtables'] = ''; + } + // Set the addpermissions items to data. if (isset($data['addpermissions']) && is_array($data['addpermissions'])) { @@ -1259,19 +1272,6 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $data['addlinked_views'] = ''; } - // Set the addtables items to data. - if (isset($data['addtables']) && is_array($data['addtables'])) - { - $addtables = new JRegistry; - $addtables->loadArray($data['addtables']); - $data['addtables'] = (string) $addtables; - } - elseif (!isset($data['addtables'])) - { - // Set the empty addtables to data - $data['addtables'] = ''; - } - // Set the alias_builder items to data. if (isset($data['alias_builder']) && is_array($data['alias_builder'])) { @@ -1311,6 +1311,12 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $data['ajax_input'] = ''; } + // Set the php_import_headers string to base64 string. + if (isset($data['php_import_headers'])) + { + $data['php_import_headers'] = base64_encode($data['php_import_headers']); + } + // Set the html_import_view string to base64 string. if (isset($data['html_import_view'])) { @@ -1323,10 +1329,10 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $data['php_import_save'] = base64_encode($data['php_import_save']); } - // Set the php_import_headers string to base64 string. - if (isset($data['php_import_headers'])) + // Set the php_getitem string to base64 string. + if (isset($data['php_getitem'])) { - $data['php_import_headers'] = base64_encode($data['php_import_headers']); + $data['php_getitem'] = base64_encode($data['php_getitem']); } // Set the php_getitems string to base64 string. @@ -1341,108 +1347,108 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $data['php_getitems_after_all'] = base64_encode($data['php_getitems_after_all']); } - // Set the css_view string to base64 string. - if (isset($data['css_view'])) - { - $data['css_view'] = base64_encode($data['css_view']); - } - // Set the php_getlistquery string to base64 string. if (isset($data['php_getlistquery'])) { $data['php_getlistquery'] = base64_encode($data['php_getlistquery']); } + // Set the css_view string to base64 string. + if (isset($data['css_view'])) + { + $data['css_view'] = base64_encode($data['css_view']); + } + // Set the php_getform string to base64 string. if (isset($data['php_getform'])) { $data['php_getform'] = base64_encode($data['php_getform']); } - // Set the css_views string to base64 string. - if (isset($data['css_views'])) - { - $data['css_views'] = base64_encode($data['css_views']); - } - // Set the php_before_save string to base64 string. if (isset($data['php_before_save'])) { $data['php_before_save'] = base64_encode($data['php_before_save']); } + // Set the css_views string to base64 string. + if (isset($data['css_views'])) + { + $data['css_views'] = base64_encode($data['css_views']); + } + // Set the php_save string to base64 string. if (isset($data['php_save'])) { $data['php_save'] = base64_encode($data['php_save']); } - // Set the javascript_view_file string to base64 string. - if (isset($data['javascript_view_file'])) - { - $data['javascript_view_file'] = base64_encode($data['javascript_view_file']); - } - // Set the php_postsavehook string to base64 string. if (isset($data['php_postsavehook'])) { $data['php_postsavehook'] = base64_encode($data['php_postsavehook']); } + // Set the javascript_view_file string to base64 string. + if (isset($data['javascript_view_file'])) + { + $data['javascript_view_file'] = base64_encode($data['javascript_view_file']); + } + // Set the php_allowadd string to base64 string. if (isset($data['php_allowadd'])) { $data['php_allowadd'] = base64_encode($data['php_allowadd']); } - // Set the javascript_view_footer string to base64 string. - if (isset($data['javascript_view_footer'])) - { - $data['javascript_view_footer'] = base64_encode($data['javascript_view_footer']); - } - // Set the php_allowedit string to base64 string. if (isset($data['php_allowedit'])) { $data['php_allowedit'] = base64_encode($data['php_allowedit']); } + // Set the javascript_view_footer string to base64 string. + if (isset($data['javascript_view_footer'])) + { + $data['javascript_view_footer'] = base64_encode($data['javascript_view_footer']); + } + // Set the php_batchcopy string to base64 string. if (isset($data['php_batchcopy'])) { $data['php_batchcopy'] = base64_encode($data['php_batchcopy']); } - // Set the javascript_views_file string to base64 string. - if (isset($data['javascript_views_file'])) - { - $data['javascript_views_file'] = base64_encode($data['javascript_views_file']); - } - // Set the php_batchmove string to base64 string. if (isset($data['php_batchmove'])) { $data['php_batchmove'] = base64_encode($data['php_batchmove']); } + // Set the javascript_views_file string to base64 string. + if (isset($data['javascript_views_file'])) + { + $data['javascript_views_file'] = base64_encode($data['javascript_views_file']); + } + // Set the php_before_publish string to base64 string. if (isset($data['php_before_publish'])) { $data['php_before_publish'] = base64_encode($data['php_before_publish']); } - // Set the javascript_views_footer string to base64 string. - if (isset($data['javascript_views_footer'])) - { - $data['javascript_views_footer'] = base64_encode($data['javascript_views_footer']); - } - // Set the php_after_publish string to base64 string. if (isset($data['php_after_publish'])) { $data['php_after_publish'] = base64_encode($data['php_after_publish']); } + // Set the javascript_views_footer string to base64 string. + if (isset($data['javascript_views_footer'])) + { + $data['javascript_views_footer'] = base64_encode($data['javascript_views_footer']); + } + // Set the php_before_delete string to base64 string. if (isset($data['php_before_delete'])) { @@ -1455,36 +1461,36 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $data['php_after_delete'] = base64_encode($data['php_after_delete']); } - // Set the php_controller string to base64 string. - if (isset($data['php_controller'])) - { - $data['php_controller'] = base64_encode($data['php_controller']); - } - // Set the php_document string to base64 string. if (isset($data['php_document'])) { $data['php_document'] = base64_encode($data['php_document']); } + // Set the php_controller string to base64 string. + if (isset($data['php_controller'])) + { + $data['php_controller'] = base64_encode($data['php_controller']); + } + // Set the php_model string to base64 string. if (isset($data['php_model'])) { $data['php_model'] = base64_encode($data['php_model']); } - // Set the php_controller_list string to base64 string. - if (isset($data['php_controller_list'])) - { - $data['php_controller_list'] = base64_encode($data['php_controller_list']); - } - // Set the sql string to base64 string. if (isset($data['sql'])) { $data['sql'] = base64_encode($data['sql']); } + // Set the php_controller_list string to base64 string. + if (isset($data['php_controller_list'])) + { + $data['php_controller_list'] = base64_encode($data['php_controller_list']); + } + // Set the php_model_list string to base64 string. if (isset($data['php_model_list'])) { @@ -1497,18 +1503,18 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin $data['php_import_display'] = base64_encode($data['php_import_display']); } - // Set the php_ajaxmethod string to base64 string. - if (isset($data['php_ajaxmethod'])) - { - $data['php_ajaxmethod'] = base64_encode($data['php_ajaxmethod']); - } - // Set the php_import string to base64 string. if (isset($data['php_import'])) { $data['php_import'] = base64_encode($data['php_import']); } + // Set the php_ajaxmethod string to base64 string. + if (isset($data['php_ajaxmethod'])) + { + $data['php_ajaxmethod'] = base64_encode($data['php_ajaxmethod']); + } + // Set the php_import_setdata string to base64 string. if (isset($data['php_import_setdata'])) { @@ -1519,12 +1525,6 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin if (isset($data['php_import_ext'])) { $data['php_import_ext'] = base64_encode($data['php_import_ext']); - } - - // Set the php_getitem string to base64 string. - if (isset($data['php_getitem'])) - { - $data['php_getitem'] = base64_encode($data['php_getitem']); } // Set the Params Items to data diff --git a/admin/models/admin_views.php b/admin/models/admin_views.php index 675d3fd77..50df7be90 100644 --- a/admin/models/admin_views.php +++ b/admin/models/admin_views.php @@ -31,8 +31,8 @@ class ComponentbuilderModelAdmin_views extends JModelList 'a.name_single','name_single', 'a.short_description','short_description', 'a.add_fadein','add_fadein', - 'a.type','type', 'a.add_custom_import','add_custom_import', + 'a.type','type', 'a.add_custom_button','add_custom_button', 'a.add_php_ajax','add_php_ajax' ); @@ -67,12 +67,12 @@ class ComponentbuilderModelAdmin_views extends JModelList $add_fadein = $this->getUserStateFromRequest($this->context . '.filter.add_fadein', 'filter_add_fadein'); $this->setState('filter.add_fadein', $add_fadein); - $type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type'); - $this->setState('filter.type', $type); - $add_custom_import = $this->getUserStateFromRequest($this->context . '.filter.add_custom_import', 'filter_add_custom_import'); $this->setState('filter.add_custom_import', $add_custom_import); + $type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type'); + $this->setState('filter.type', $type); + $add_custom_button = $this->getUserStateFromRequest($this->context . '.filter.add_custom_button', 'filter_add_custom_button'); $this->setState('filter.add_custom_button', $add_custom_button); @@ -136,10 +136,10 @@ class ComponentbuilderModelAdmin_views extends JModelList { // convert add_fadein $item->add_fadein = $this->selectionTranslation($item->add_fadein, 'add_fadein'); - // convert type - $item->type = $this->selectionTranslation($item->type, 'type'); // convert add_custom_import $item->add_custom_import = $this->selectionTranslation($item->add_custom_import, 'add_custom_import'); + // convert type + $item->type = $this->selectionTranslation($item->type, 'type'); // convert add_custom_button $item->add_custom_button = $this->selectionTranslation($item->add_custom_button, 'add_custom_button'); // convert add_php_ajax @@ -172,19 +172,6 @@ class ComponentbuilderModelAdmin_views extends JModelList return $add_fadeinArray[$value]; } } - // Array of type language strings - if ($name === 'type') - { - $typeArray = array( - 1 => 'COM_COMPONENTBUILDER_ADMIN_VIEW_READWRITE', - 2 => 'COM_COMPONENTBUILDER_ADMIN_VIEW_READONLY' - ); - // Now check if value is found in this array - if (isset($typeArray[$value]) && ComponentbuilderHelper::checkString($typeArray[$value])) - { - return $typeArray[$value]; - } - } // Array of add_custom_import language strings if ($name === 'add_custom_import') { @@ -198,6 +185,19 @@ class ComponentbuilderModelAdmin_views extends JModelList return $add_custom_importArray[$value]; } } + // Array of type language strings + if ($name === 'type') + { + $typeArray = array( + 1 => 'COM_COMPONENTBUILDER_ADMIN_VIEW_READWRITE', + 2 => 'COM_COMPONENTBUILDER_ADMIN_VIEW_READONLY' + ); + // Now check if value is found in this array + if (isset($typeArray[$value]) && ComponentbuilderHelper::checkString($typeArray[$value])) + { + return $typeArray[$value]; + } + } // Array of add_custom_button language strings if ($name === 'add_custom_button') { @@ -282,7 +282,7 @@ class ComponentbuilderModelAdmin_views extends JModelList else { $search = $db->quote('%' . $db->escape($search) . '%'); - $query->where('(a.system_name LIKE '.$search.' OR a.name_single LIKE '.$search.' OR a.short_description LIKE '.$search.' OR a.description LIKE '.$search.' OR a.type LIKE '.$search.' OR a.name_list LIKE '.$search.')'); + $query->where('(a.system_name LIKE '.$search.' OR a.name_single LIKE '.$search.' OR a.short_description LIKE '.$search.' OR a.description LIKE '.$search.' OR a.name_list LIKE '.$search.' OR a.type LIKE '.$search.')'); } } @@ -291,16 +291,16 @@ class ComponentbuilderModelAdmin_views extends JModelList { $query->where('a.add_fadein = ' . $db->quote($db->escape($add_fadein))); } - // Filter by Type. - if ($type = $this->getState('filter.type')) - { - $query->where('a.type = ' . $db->quote($db->escape($type))); - } // Filter by Add_custom_import. if ($add_custom_import = $this->getState('filter.add_custom_import')) { $query->where('a.add_custom_import = ' . $db->quote($db->escape($add_custom_import))); } + // Filter by Type. + if ($type = $this->getState('filter.type')) + { + $query->where('a.type = ' . $db->quote($db->escape($type))); + } // Filter by Add_custom_button. if ($add_custom_button = $this->getState('filter.add_custom_button')) { @@ -376,78 +376,78 @@ class ComponentbuilderModelAdmin_views extends JModelList continue; } + // decode php_import_headers + $item->php_import_headers = base64_decode($item->php_import_headers); // decode html_import_view $item->html_import_view = base64_decode($item->html_import_view); // decode php_import_save $item->php_import_save = base64_decode($item->php_import_save); - // decode php_import_headers - $item->php_import_headers = base64_decode($item->php_import_headers); + // decode php_getitem + $item->php_getitem = base64_decode($item->php_getitem); // decode php_getitems $item->php_getitems = base64_decode($item->php_getitems); // decode php_getitems_after_all $item->php_getitems_after_all = base64_decode($item->php_getitems_after_all); - // decode css_view - $item->css_view = base64_decode($item->css_view); // decode php_getlistquery $item->php_getlistquery = base64_decode($item->php_getlistquery); + // decode css_view + $item->css_view = base64_decode($item->css_view); // decode php_getform $item->php_getform = base64_decode($item->php_getform); - // decode css_views - $item->css_views = base64_decode($item->css_views); // decode php_before_save $item->php_before_save = base64_decode($item->php_before_save); + // decode css_views + $item->css_views = base64_decode($item->css_views); // decode php_save $item->php_save = base64_decode($item->php_save); - // decode javascript_view_file - $item->javascript_view_file = base64_decode($item->javascript_view_file); // decode php_postsavehook $item->php_postsavehook = base64_decode($item->php_postsavehook); + // decode javascript_view_file + $item->javascript_view_file = base64_decode($item->javascript_view_file); // decode php_allowadd $item->php_allowadd = base64_decode($item->php_allowadd); - // decode javascript_view_footer - $item->javascript_view_footer = base64_decode($item->javascript_view_footer); // decode php_allowedit $item->php_allowedit = base64_decode($item->php_allowedit); + // decode javascript_view_footer + $item->javascript_view_footer = base64_decode($item->javascript_view_footer); // decode php_batchcopy $item->php_batchcopy = base64_decode($item->php_batchcopy); - // decode javascript_views_file - $item->javascript_views_file = base64_decode($item->javascript_views_file); // decode php_batchmove $item->php_batchmove = base64_decode($item->php_batchmove); + // decode javascript_views_file + $item->javascript_views_file = base64_decode($item->javascript_views_file); // decode php_before_publish $item->php_before_publish = base64_decode($item->php_before_publish); - // decode javascript_views_footer - $item->javascript_views_footer = base64_decode($item->javascript_views_footer); // decode php_after_publish $item->php_after_publish = base64_decode($item->php_after_publish); + // decode javascript_views_footer + $item->javascript_views_footer = base64_decode($item->javascript_views_footer); // decode php_before_delete $item->php_before_delete = base64_decode($item->php_before_delete); // decode php_after_delete $item->php_after_delete = base64_decode($item->php_after_delete); - // decode php_controller - $item->php_controller = base64_decode($item->php_controller); // decode php_document $item->php_document = base64_decode($item->php_document); + // decode php_controller + $item->php_controller = base64_decode($item->php_controller); // decode php_model $item->php_model = base64_decode($item->php_model); - // decode php_controller_list - $item->php_controller_list = base64_decode($item->php_controller_list); // decode sql $item->sql = base64_decode($item->sql); + // decode php_controller_list + $item->php_controller_list = base64_decode($item->php_controller_list); // decode php_model_list $item->php_model_list = base64_decode($item->php_model_list); // decode php_import_display $item->php_import_display = base64_decode($item->php_import_display); - // decode php_ajaxmethod - $item->php_ajaxmethod = base64_decode($item->php_ajaxmethod); // decode php_import $item->php_import = base64_decode($item->php_import); + // decode php_ajaxmethod + $item->php_ajaxmethod = base64_decode($item->php_ajaxmethod); // decode php_import_setdata $item->php_import_setdata = base64_decode($item->php_import_setdata); // decode php_import_ext $item->php_import_ext = base64_decode($item->php_import_ext); - // decode php_getitem - $item->php_getitem = base64_decode($item->php_getitem); // unset the values we don't want exported. unset($item->asset_id); unset($item->checked_out); @@ -512,8 +512,8 @@ class ComponentbuilderModelAdmin_views extends JModelList $id .= ':' . $this->getState('filter.name_single'); $id .= ':' . $this->getState('filter.short_description'); $id .= ':' . $this->getState('filter.add_fadein'); - $id .= ':' . $this->getState('filter.type'); $id .= ':' . $this->getState('filter.add_custom_import'); + $id .= ':' . $this->getState('filter.type'); $id .= ':' . $this->getState('filter.add_custom_button'); $id .= ':' . $this->getState('filter.add_php_ajax'); diff --git a/admin/models/admins_custom_tabs.php b/admin/models/admins_custom_tabs.php new file mode 100644 index 000000000..d0fadf824 --- /dev/null +++ b/admin/models/admins_custom_tabs.php @@ -0,0 +1,237 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +/** + * Admins_custom_tabs Model + */ +class ComponentbuilderModelAdmins_custom_tabs extends JModelList +{ + public function __construct($config = array()) + { + if (empty($config['filter_fields'])) + { + $config['filter_fields'] = array( + 'a.id','id', + 'a.published','published', + 'a.ordering','ordering', + 'a.created_by','created_by', + 'a.modified_by','modified_by' + ); + } + + parent::__construct($config); + } + + /** + * Method to auto-populate the model state. + * + * @return void + */ + protected function populateState($ordering = null, $direction = null) + { + $app = JFactory::getApplication(); + + // Adjust the context to support modal layouts. + if ($layout = $app->input->get('layout')) + { + $this->context .= '.' . $layout; + } + + + $sorting = $this->getUserStateFromRequest($this->context . '.filter.sorting', 'filter_sorting', 0, 'int'); + $this->setState('filter.sorting', $sorting); + + $access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', 0, 'int'); + $this->setState('filter.access', $access); + + $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); + $this->setState('filter.search', $search); + + $published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', ''); + $this->setState('filter.published', $published); + + $created_by = $this->getUserStateFromRequest($this->context . '.filter.created_by', 'filter_created_by', ''); + $this->setState('filter.created_by', $created_by); + + $created = $this->getUserStateFromRequest($this->context . '.filter.created', 'filter_created'); + $this->setState('filter.created', $created); + + // List state information. + parent::populateState($ordering, $direction); + } + + /** + * Method to get an array of data items. + * + * @return mixed An array of data items on success, false on failure. + */ + public function getItems() + { + // check in items + $this->checkInNow(); + + // load parent items + $items = parent::getItems(); + + // set values to display correctly. + if (ComponentbuilderHelper::checkArray($items)) + { + foreach ($items as $nr => &$item) + { + $access = (JFactory::getUser()->authorise('admin_custom_tabs.access', 'com_componentbuilder.admin_custom_tabs.' . (int) $item->id) && JFactory::getUser()->authorise('admin_custom_tabs.access', 'com_componentbuilder')); + if (!$access) + { + unset($items[$nr]); + continue; + } + + } + } + + // return items + return $items; + } + + /** + * Method to build an SQL query to load the list data. + * + * @return string An SQL query + */ + protected function getListQuery() + { + // Get the user object. + $user = JFactory::getUser(); + // Create a new query object. + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + + // Select some fields + $query->select('a.*'); + + // From the componentbuilder_item table + $query->from($db->quoteName('#__componentbuilder_admin_custom_tabs', 'a')); + + // From the componentbuilder_admin_view table. + $query->select($db->quoteName('g.system_name','admin_view_system_name')); + $query->join('LEFT', $db->quoteName('#__componentbuilder_admin_view', 'g') . ' ON (' . $db->quoteName('a.admin_view') . ' = ' . $db->quoteName('g.id') . ')'); + + // Filter by published state + $published = $this->getState('filter.published'); + if (is_numeric($published)) + { + $query->where('a.published = ' . (int) $published); + } + elseif ($published === '') + { + $query->where('(a.published = 0 OR a.published = 1)'); + } + + // Join over the asset groups. + $query->select('ag.title AS access_level'); + $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); + // Filter by access level. + if ($access = $this->getState('filter.access')) + { + $query->where('a.access = ' . (int) $access); + } + // Implement View Level Access + if (!$user->authorise('core.options', 'com_componentbuilder')) + { + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + } + + // Add the list ordering clause. + $orderCol = $this->state->get('list.ordering', 'a.id'); + $orderDirn = $this->state->get('list.direction', 'asc'); + if ($orderCol != '') + { + $query->order($db->escape($orderCol . ' ' . $orderDirn)); + } + + return $query; + } + + /** + * Method to get a store id based on model configuration state. + * + * @return string A store id. + * + */ + protected function getStoreId($id = '') + { + // Compile the store id. + $id .= ':' . $this->getState('filter.id'); + $id .= ':' . $this->getState('filter.search'); + $id .= ':' . $this->getState('filter.published'); + $id .= ':' . $this->getState('filter.ordering'); + $id .= ':' . $this->getState('filter.created_by'); + $id .= ':' . $this->getState('filter.modified_by'); + + return parent::getStoreId($id); + } + + /** + * Build an SQL query to checkin all items left checked out longer then a set time. + * + * @return a bool + * + */ + protected function checkInNow() + { + // Get set check in time + $time = JComponentHelper::getParams('com_componentbuilder')->get('check_in'); + + if ($time) + { + + // Get a db connection. + $db = JFactory::getDbo(); + // reset query + $query = $db->getQuery(true); + $query->select('*'); + $query->from($db->quoteName('#__componentbuilder_admin_custom_tabs')); + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + // Get Yesterdays date + $date = JFactory::getDate()->modify($time)->toSql(); + // reset query + $query = $db->getQuery(true); + + // Fields to update. + $fields = array( + $db->quoteName('checked_out_time') . '=\'0000-00-00 00:00:00\'', + $db->quoteName('checked_out') . '=0' + ); + + // Conditions for which records should be updated. + $conditions = array( + $db->quoteName('checked_out') . '!=0', + $db->quoteName('checked_out_time') . '<\''.$date.'\'' + ); + + // Check table + $query->update($db->quoteName('#__componentbuilder_admin_custom_tabs'))->set($fields)->where($conditions); + + $db->setQuery($query); + + $db->execute(); + } + } + + return false; + } +} diff --git a/admin/models/ajax.php b/admin/models/ajax.php index 94aea773f..00ed318f7 100644 --- a/admin/models/ajax.php +++ b/admin/models/ajax.php @@ -251,6 +251,7 @@ class ComponentbuilderModelAjax extends JModelList 'admin_fields' => 'admins_fields', 'admin_fields_conditions' => 'admins_fields_conditions', 'admin_fields_relations' => 'admins_fields_relations', + 'admin_custom_tabs' => 'admins_custom_tabs', 'validation_rule' => 'validation_rules', 'field' => 'fields', 'component_admin_views' => 'components_admin_views' , diff --git a/admin/models/componentbuilder.php b/admin/models/componentbuilder.php index 65167314a..034a34a70 100644 --- a/admin/models/componentbuilder.php +++ b/admin/models/componentbuilder.php @@ -130,6 +130,9 @@ class ComponentbuilderModelComponentbuilder extends JModelList 'admin_fields_relations.create' => 'admin_fields_relations.create', 'admins_fields_relations.access' => 'admin_fields_relations.access', 'admin_fields_relations.access' => 'admin_fields_relations.access', + 'admin_custom_tabs.create' => 'admin_custom_tabs.create', + 'admins_custom_tabs.access' => 'admin_custom_tabs.access', + 'admin_custom_tabs.access' => 'admin_custom_tabs.access', 'component_admin_views.create' => 'component_admin_views.create', 'components_admin_views.access' => 'component_admin_views.access', 'component_admin_views.access' => 'component_admin_views.access', diff --git a/admin/models/fields/viewtabs.php b/admin/models/fields/viewtabs.php index 58c3358f5..e21e65508 100644 --- a/admin/models/fields/viewtabs.php +++ b/admin/models/fields/viewtabs.php @@ -35,37 +35,55 @@ class JFormFieldViewtabs extends JFormFieldList */ public function getOptions() { - // get the input from url - $jinput = JFactory::getApplication()->input; - // get the view name & id - $fieldsID = $jinput->getInt('id', 0); - $db = JFactory::getDBO(); - $query = $db->getQuery(true); - $query->select($db->quoteName(array('a.id','a.addtabs'),array('id','addtabs'))); - $query->from($db->quoteName('#__componentbuilder_admin_view', 'a')); - $query->join('LEFT', $db->quoteName('#__componentbuilder_admin_fields', 'b') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('b.admin_view') . ')'); - $query->where($db->quoteName('a.published') . ' >= 1'); - $query->where($db->quoteName('b.id') . ' = ' . (int) $fieldsID); - $query->order('a.addtabs ASC'); - $db->setQuery((string)$query); - $item = $db->loadObject(); - $options = array(); - if (isset($item->addtabs) && strlen($item->addtabs) > 5) - { - $items = json_decode($item->addtabs, true); - $nr = 1; - foreach($items as $itemName) - { - $options[] = JHtml::_('select.option', $nr, $itemName['name']); - $nr++; - } + // get the input from url + $jinput = JFactory::getApplication()->input; + // get the view name & id + $fieldsID = $jinput->getInt('id', 0); + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id','a.addtabs'),array('id','addtabs'))); + $query->from($db->quoteName('#__componentbuilder_admin_view', 'a')); + if ($fieldsID > 0) + { + $query->join('LEFT', $db->quoteName('#__componentbuilder_admin_fields', 'b') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('b.admin_view') . ')'); + $query->where($db->quoteName('b.id') . ' = ' . (int) $fieldsID); + } + else + { + // get the refs if found + $ref = $jinput->get('ref', 0, 'WORD'); + $refid = $jinput->getInt('refid', 0); + if ('admin_view' === $ref && $refid > 0) + { + $query->where($db->quoteName('a.id') . ' = ' . (int) $refid); + } + else + { + // kry maar niks + $query->where($db->quoteName('a.id') . ' = 0'); + } + } + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->order('a.addtabs ASC'); + $db->setQuery((string)$query); + $item = $db->loadObject(); + $options = array(); + if (isset($item->addtabs) && strlen($item->addtabs) > 5) + { + $items = json_decode($item->addtabs, true); + $nr = 1; + foreach($items as $itemName) + { + $options[] = JHtml::_('select.option', $nr, $itemName['name']); + $nr++; + } } else { $options[] = JHtml::_('select.option', 1, JText::_('COM_COMPONENTBUILDER_DETAILS')); } // add the default publish tab as an option - $options[] = JHtml::_('select.option', 15, JText::_('COM_COMPONENTBUILDER_PUBLISHING')); + $options[] = JHtml::_('select.option', 15, JText::_('COM_COMPONENTBUILDER_PUBLISHING')); return $options; } } diff --git a/admin/models/forms/admin_custom_tabs.js b/admin/models/forms/admin_custom_tabs.js new file mode 100644 index 000000000..4bb347a82 --- /dev/null +++ b/admin/models/forms/admin_custom_tabs.js @@ -0,0 +1,11 @@ +/** + * @package Joomla.Component.Builder + * + * @created 30th April, 2015 + * @author Llewellyn van der Merwe + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + + diff --git a/admin/models/forms/admin_custom_tabs.xml b/admin/models/forms/admin_custom_tabs.xml new file mode 100644 index 000000000..e6b8e319f --- /dev/null +++ b/admin/models/forms/admin_custom_tabs.xml @@ -0,0 +1,203 @@ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + +
+ \ No newline at end of file diff --git a/admin/models/forms/admin_view.js b/admin/models/forms/admin_view.js index aa2e0ff50..0ca3b2431 100644 --- a/admin/models/forms/admin_view.js +++ b/admin/models/forms/admin_view.js @@ -1273,6 +1273,8 @@ jQuery(document).ready(function() addButton('field','create_edit_buttons'); // <-- third // set button addButtonID('admin_fields_relations','create_edit_buttons', 1); // <-- forth + // set button + addButtonID('admin_custom_tabs','addtabs-lbl', 1); // <-- fifth }); function checkAliasField() { diff --git a/admin/models/forms/admin_view.xml b/admin/models/forms/admin_view.xml index df0cfb913..1542617ed 100644 --- a/admin/models/forms/admin_view.xml +++ b/admin/models/forms/admin_view.xml @@ -128,11 +128,11 @@ message="COM_COMPONENTBUILDER_ADMIN_VIEW_SHORT_DESCRIPTION_MESSAGE" hint="COM_COMPONENTBUILDER_ADMIN_VIEW_SHORT_DESCRIPTION_HINT" /> - + @@ -142,11 +142,11 @@ - + @@ -156,11 +156,11 @@ - + @@ -170,11 +170,11 @@ - + @@ -184,25 +184,11 @@ - + - - - - - - @@ -220,11 +206,11 @@ description="COM_COMPONENTBUILDER_ADMIN_VIEW_ICON_DESCRIPTION" directory="" /> - + @@ -278,11 +264,11 @@ description="COM_COMPONENTBUILDER_ADMIN_VIEW_ICON_ADD_DESCRIPTION" directory="" /> - + @@ -292,24 +278,12 @@ - - - + @@ -319,6 +293,71 @@ + + + + + + + + + + +