Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'feature/productgroup-access' into develop

  • Loading branch information...
commit 6b047c1d7f63bf45a6c264ee006e67e2292e04d0 2 parents 1efe02c + af27616
@aschempp aschempp authored
View
33 system/drivers/DC_ProductData.php
@@ -50,7 +50,7 @@ class DC_ProductData extends DC_Table
* @var array
*/
protected $arrLanguages;
-
+
/**
* Array of language labels
* @var array
@@ -1522,6 +1522,19 @@ protected function treeView()
$this->loadLanguageFile($gtable);
$this->loadDataContainer($gtable);
+
+ // Call onload_callback (e.g. to check permissions)
+ if (is_array($GLOBALS['TL_DCA'][$gtable]['config']['onload_callback']))
+ {
+ foreach ($GLOBALS['TL_DCA'][$gtable]['config']['onload_callback'] as $callback)
+ {
+ if (is_array($callback))
+ {
+ $this->import($callback[0]);
+ $this->$callback[0]->$callback[1]($this);
+ }
+ }
+ }
}
// Return if a mandatory field (id, pid) is missing
@@ -1633,28 +1646,12 @@ protected function treeView()
$this->Session->set('PRODUCTDATA_OVERLOAD', true);
// Call a recursive function that builds the tree including groups
- $this->root = $this->Database->query("SELECT id FROM $gtable WHERE pid=0 ORDER BY sorting")->fetchEach('id');
+ $this->root = is_array($GLOBALS['TL_DCA'][$gtable]['list']['sorting']['root']) ? $this->eliminateNestedPages($GLOBALS['TL_DCA'][$gtable]['list']['sorting']['root'], $gtable, true) : $this->Database->query("SELECT id FROM $gtable WHERE pid=0 ORDER BY sorting")->fetchEach('id');
for ($i=0, $count=count($this->root); $i<$count; $i++)
{
$tree .= $this->generateProductTree($gtable, $this->root[$i], array('p'=>$this->root[($i-1)], 'n'=>$this->root[($i+1)]), -20, ($blnClipboard ? $arrClipboard : false));
}
- // Generate all products not in a group
- if ($GLOBALS['TL_CONFIG']['iso_deferProductLoading'])
- {
- $root = $this->Database->query("SELECT id FROM $table WHERE pid=0 AND gid=0")->fetchEach('id');
- $this->root = array_values(array_intersect($this->products, $root));
- }
- else
- {
- $this->root = $this->Database->query("SELECT id FROM $table WHERE pid=0 AND gid=0 AND id IN (" . implode(',', $this->products) . ") ORDER BY id=" . implode(' DESC, id=', $this->products) . " DESC")->fetchEach('id');
- }
-
- for ($i=0, $count=count($this->root); $i<$count; $i++)
- {
- $tree .= $this->generateProductTree($table, $this->root[$i], array('p'=>$this->root[($i-1)], 'n'=>$this->root[($i+1)]), -20, ($blnClipboard ? $arrClipboard : false));
- }
-
// Stop the overload detection, everything went smoothly
$this->Session->set('PRODUCTDATA_OVERLOAD', false);
View
27 system/modules/isotope/IsotopeBackend.php
@@ -532,5 +532,32 @@ public function getOrderMessages()
return implode("\n", $arrMessages);
}
+
+
+ /**
+ * Generate the GENERAL group if there is none
+ * @return boolean
+ */
+ public static function createGeneralGroup()
+ {
+ $objDatabase = Database::getInstance();
+
+ $objGroups = $objDatabase->executeUncached("SELECT COUNT(id) AS total FROM tl_iso_groups");
+
+ if ($objGroups->total == 0)
+ {
+ $intGroup = $objDatabase->executeUncached("INSERT INTO tl_iso_groups (pid,sorting,tstamp,name) VALUES (0, 0, " . time() . ", '### GENERAL ###')")->insertId;
+
+ // add all products to that new folder
+ $objDatabase->query("UPDATE tl_iso_products SET gid=$intGroup WHERE pid=0 AND language='' AND gid=0");
+
+ // toggle (open) the new group
+ Session::getInstance()->set('tl_iso_products_tl_iso_groups_tree', array($intGroup=>1));
+
+ return true;
+ }
+
+ return false;
+ }
}
View
19 system/modules/isotope/UPDATE-1.4.md
@@ -0,0 +1,19 @@
+UPDATE FROM 1.3 to 1.4
+=======================
+
+### General
+
+ * A general info:
+
+ Lorem Ipsum
+
+ * Another one
+
+ Lorem Ipsum
+
+### Products
+
+ * Product group permissions
+
+ You can now limit the access to product groups. An outcome of this new feature is that you can't have any product assigned to no product group
+ at all anymore. The update will take care of that for you.
View
2  system/modules/isotope/config/config.php
@@ -262,6 +262,8 @@
$GLOBALS['TL_PERMISSIONS'][] = 'iso_mailp';
$GLOBALS['TL_PERMISSIONS'][] = 'iso_configs';
$GLOBALS['TL_PERMISSIONS'][] = 'iso_configp';
+$GLOBALS['TL_PERMISSIONS'][] = 'iso_groups';
+$GLOBALS['TL_PERMISSIONS'][] = 'iso_groupp';
/**
View
4 system/modules/isotope/config/database.sql
@@ -839,6 +839,8 @@ CREATE TABLE `tl_user` (
`iso_mailp` blob NULL,
`iso_configs` blob NULL,
`iso_configp` blob NULL,
+ `iso_groups` blob NULL
+ `iso_groupp` blob NULL,
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -864,6 +866,8 @@ CREATE TABLE `tl_user_group` (
`iso_mailp` blob NULL,
`iso_configs` blob NULL,
`iso_configp` blob NULL,
+ `iso_groups` blob NULL
+ `iso_groupp` blob NULL,
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
View
25 system/modules/isotope/config/runonce.php
@@ -66,6 +66,7 @@ public function run()
$this->exec('updateProductTypes');
$this->exec('updateRules');
$this->exec('generateCategoryGroups');
+ $this->exec('createGroupForAllNonAssignedProducts');
// Make sure file extension .imt (Isotope Mail Template) is allowed for up- and download
if (!in_array('imt', trimsplit(',', $GLOBALS['TL_CONFIG']['uploadTypes'])))
@@ -977,6 +978,30 @@ private function generateCategoryGroups()
}
}
}
+
+
+ /**
+ * In Isotope 1.4 every product has to be assigned to a product groups for access permissions
+ */
+ private function createGroupForAllNonAssignedProducts()
+ {
+ if (!$this->Database->tableExists('tl_iso_groups') || !$this->Database->tableExists('tl_iso_products'))
+ {
+ return;
+ }
+
+ $objNoGroupProducts = $this->Database->executeUncached("SELECT COUNT(id) AS total FROM tl_iso_products WHERE pid=0 AND language='' AND gid=0");
+
+ if ($objNoGroupProducts->total < 1)
+ {
+ return;
+ }
+
+ // generate a group, we can't take an existing one because we dont know which one to use
+ $intGroup = $this->Database->executeUncached("INSERT INTO tl_iso_groups (pid,sorting,tstamp,name) VALUES (0, 0, " . time() . ", '### GENERAL ###')")->insertId;
+
+ $this->Database->query("UPDATE tl_iso_products SET gid=$intGroup WHERE pid=0 AND language='' AND gid=0");
+ }
}
View
100 system/modules/isotope/dca/tl_iso_groups.php
@@ -40,6 +40,10 @@
'dataContainer' => 'Table',
'label' => &$GLOBALS['TL_LANG']['tl_iso_groups']['label'],
'enableVersioning' => true,
+ 'onload_callback' => array
+ (
+ array('tl_iso_groups', 'checkPermission'),
+ ),
'ondelete_callback' => array
(
array('tl_iso_groups', 'deleteGroup'),
@@ -84,7 +88,8 @@
(
'label' => &$GLOBALS['TL_LANG']['tl_iso_groups']['copy'],
'href' => 'table=tl_iso_groups&amp;act=paste&amp;mode=copy',
- 'icon' => 'copy.gif'
+ 'icon' => 'copy.gif',
+ 'button_callback' => array('tl_iso_groups', 'copyButton'),
),
'cut' => array
(
@@ -98,7 +103,8 @@
'label' => &$GLOBALS['TL_LANG']['tl_iso_groups']['delete'],
'href' => 'table=tl_iso_groups&amp;act=delete',
'icon' => 'delete.gif',
- 'attributes' => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"'
+ 'attributes' => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"',
+ 'button_callback' => array('tl_iso_groups', 'deleteButton'),
),
'show' => array
(
@@ -136,6 +142,52 @@
class tl_iso_groups extends Backend
{
+ public function __construct()
+ {
+ parent::__construct();
+ $this->import('BackendUser', 'User');
+ }
+
+
+ /**
+ * Check access permissions
+ */
+ public function checkPermission($dc)
+ {
+ if ($this->User->isAdmin)
+ {
+ return;
+ }
+
+ // Load permissions in tl_iso_products
+ if ($dc->table == 'tl_iso_products')
+ {
+ $GLOBALS['TL_DCA']['tl_iso_groups']['list']['sorting']['root'] = (array) $this->User->iso_groups;
+ return;
+ }
+
+ if (!is_array($this->User->iso_groupp) || empty($this->User->iso_groupp) || !is_array($this->User->iso_groups) || empty($this->User->iso_groups))
+ {
+ $this->log('Unallowed access to product groups!', __METHOD__, TL_ERROR);
+ $this->redirect('contao/main.php?act=error');
+ }
+
+ $GLOBALS['TL_DCA']['tl_iso_groups']['list']['sorting']['root'] = $this->User->iso_groups;
+
+ if (!in_array('create', $this->User->iso_groupp))
+ {
+ $GLOBALS['TL_DCA']['tl_iso_groups']['config']['closed'] = true;
+ }
+
+ // Check permission to delete item
+ if ($this->Input->get('act') == 'delete' && !in_array('delete', $this->User->iso_groupp))
+ {
+ $this->log('User is not allowed to delete groups', __METHOD__, TL_ERROR);
+ $this->redirect('contao/main.php?act=error');
+ }
+ }
+
+
/**
* Add an image to each group in the tree
* @param array
@@ -166,6 +218,50 @@ public function deleteGroup($dc)
$arrGroups[] = $dc->id;
$this->Database->query("UPDATE tl_iso_products SET gid=0 WHERE gid IN (" . implode(',', $arrGroups) . ")");
+
+ IsotopeBackend::createGeneralGroup();
+ }
+
+
+ /**
+ * Disable copy button if user has no permission to create groups
+ * @param array
+ * @param string
+ * @param string
+ * @param string
+ * @param string
+ * @param string
+ * @return string
+ */
+ public function copyButton($row, $href, $label, $title, $icon, $attributes)
+ {
+ if (!$this->User->isAdmin && (!is_array($this->User->iso_groupp) || !in_array('create', $this->User->iso_groupp)))
+ {
+ return $this->generateImage(preg_replace('/\.gif$/i', '_.gif', $icon)) . ' ';
+ }
+
+ return '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
+ }
+
+
+ /**
+ * Disable delete button if user has no permission to delete groups
+ * @param array
+ * @param string
+ * @param string
+ * @param string
+ * @param string
+ * @param string
+ * @return string
+ */
+ public function deleteButton($row, $href, $label, $title, $icon, $attributes)
+ {
+ if (!$this->User->isAdmin && (!is_array($this->User->iso_groupp) || !in_array('delete', $this->User->iso_groupp)))
+ {
+ return $this->generateImage(preg_replace('/\.gif$/i', '_.gif', $icon)) . ' ';
+ }
+
+ return '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
}
}
View
30 system/modules/isotope/dca/tl_iso_products.php
@@ -185,6 +185,7 @@
'href' => 'table=tl_iso_groups',
'class' => 'header_iso_groups isotope-tools',
'attributes' => 'onclick="Backend.getScrollOffset();"',
+ 'button_callback' => array('tl_iso_products', 'groupsButton')
),
'import' => array
(
@@ -725,7 +726,7 @@ public function applyAdvancedFilters()
/**
- * Only list product types a user is allowed to see
+ * Check permissions for that entry
* @return void
*/
public function checkPermission()
@@ -749,7 +750,8 @@ public function checkPermission()
return;
}
- if (!is_array($this->User->iso_product_types) || empty($this->User->iso_product_types))
+ // Filter by product type and group permissions
+ if (!is_array($this->User->iso_product_types) || empty($this->User->iso_product_types) || !is_array($this->User->iso_groups) || empty($this->User->iso_groups))
{
$GLOBALS['TL_DCA']['tl_iso_products']['config']['closed'] = true;
unset($GLOBALS['TL_DCA']['tl_iso_products']['list']['global_operations']['new_product']);
@@ -758,8 +760,9 @@ public function checkPermission()
}
else
{
- $objProducts = $this->Database->execute("SELECT id FROM tl_iso_products WHERE type IN ('','" . implode("','", $this->User->iso_product_types) . "')");
+ $arrGroups = array_merge($this->User->iso_groups, $this->getChildRecords($this->User->iso_groups, 'tl_iso_groups'));
+ $objProducts = $this->Database->execute("SELECT id FROM tl_iso_products WHERE type IN ('','" . implode("','", $this->User->iso_product_types) . "') AND gid IN (" . implode(',', $arrGroups) . ") AND pid=0 AND language=''");
$arrProducts = $objProducts->numRows ? $objProducts->fetchEach('id') : array();
// Maybe another function has already set allowed product IDs
@@ -1685,6 +1688,27 @@ public function toggleGroups($href, $label, $title, $class, $attributes, $table,
return '<a href="' . $this->addToUrl('&amp;' . $href) . '" class="header_toggle isotope-tools" title="' . specialchars($title) . '"' . $attributes . '>' . specialchars($label) . '</a>';
}
+ /**
+ * Hide "product groups" button for non-admins
+ * @param string
+ * @param string
+ * @param string
+ * @param string
+ * @param string
+ * @param string
+ * @param array
+ * @return string
+ */
+ public function groupsButton($href, $label, $title, $class, $attributes, $table, $root)
+ {
+ if (!$this->User->isAdmin && (!is_array($this->User->iso_groupp) || empty($this->User->iso_groupp) || !is_array($this->User->iso_groups) || empty($this->User->iso_groups)))
+ {
+ return '';
+ }
+
+ return '<a href="' . $this->addToUrl('&amp;' . $href) . '" class="header_iso_groups isotope-tools" title="' . specialchars($title) . '"' . $attributes . '>' . specialchars($label) . '</a>';
+ }
+
/**
* Return the "toggle visibility" button
View
38 system/modules/isotope/dca/tl_user.php
@@ -27,19 +27,18 @@
* @license http://opensource.org/licenses/lgpl-3.0.html
*/
+$this->loadLanguageFile('tl_iso_groups');
/**
* Add the Isotope style sheet
*/
$GLOBALS['TL_CSS'][] = 'system/modules/isotope/html/backend.css';
-
/**
* Extend tl_user palettes
*/
-$GLOBALS['TL_DCA']['tl_user']['palettes']['extend'] = str_replace('{account_legend}', '{isotope_legend},iso_modules,iso_product_types,iso_product_typep,iso_payment_modules,iso_payment_modulep,iso_shipping_modules,iso_shipping_modulep,iso_tax_classes,iso_tax_classp,iso_tax_rates,iso_tax_ratep,iso_mails,iso_mailp,iso_configs,iso_configp;{account_legend}', $GLOBALS['TL_DCA']['tl_user']['palettes']['extend']);
-$GLOBALS['TL_DCA']['tl_user']['palettes']['custom'] = str_replace('{account_legend}', '{isotope_legend},iso_modules,iso_product_types,iso_product_typep,iso_payment_modules,iso_payment_modulep,iso_shipping_modules,iso_shipping_modulep,iso_tax_classes,iso_tax_classp,iso_tax_rates,iso_tax_ratep,iso_mails,iso_mailp,iso_configs,iso_configp;{account_legend}', $GLOBALS['TL_DCA']['tl_user']['palettes']['custom']);
-
+$GLOBALS['TL_DCA']['tl_user']['palettes']['extend'] = str_replace('{account_legend}', '{isotope_legend},iso_modules,iso_product_types,iso_product_typep,iso_payment_modules,iso_payment_modulep,iso_shipping_modules,iso_shipping_modulep,iso_tax_classes,iso_tax_classp,iso_tax_rates,iso_tax_ratep,iso_mails,iso_mailp,iso_configs,iso_configp,iso_groups,iso_groupp;{account_legend}', $GLOBALS['TL_DCA']['tl_user']['palettes']['extend']);
+$GLOBALS['TL_DCA']['tl_user']['palettes']['custom'] = str_replace('{account_legend}', '{isotope_legend},iso_modules,iso_product_types,iso_product_typep,iso_payment_modules,iso_payment_modulep,iso_shipping_modules,iso_shipping_modulep,iso_tax_classes,iso_tax_classp,iso_tax_rates,iso_tax_ratep,iso_mails,iso_mailp,iso_configs,iso_configp,iso_groups,iso_groupp;{account_legend}', $GLOBALS['TL_DCA']['tl_user']['palettes']['custom']);
/**
* Add fields to tl_user
@@ -197,3 +196,34 @@
'eval' => array('multiple'=>true, 'tl_class'=>'w50 w50h')
);
+$GLOBALS['TL_DCA']['tl_user']['fields']['iso_groups'] = array
+(
+ 'label' => &$GLOBALS['TL_LANG']['tl_user']['iso_groups'],
+ 'exclude' => true,
+ 'inputType' => 'tableTree',
+ 'reference' => array
+ (
+ 'icon' => array
+ (
+ 'tl_iso_groups' => array('system/modules/isotope/html/folders.png', 'system/modules/isotope/html/folder-network.png')
+ )
+ ),
+ 'eval' => array
+ (
+ 'tableColumn' =>'tl_iso_groups.name',
+ 'fieldType' =>'checkbox',
+ 'title' => &$GLOBALS['TL_LANG']['tl_iso_groups']['label'],
+ 'children' => true,
+ 'tl_class' =>'clr'
+ )
+);
+
+$GLOBALS['TL_DCA']['tl_user']['fields']['iso_groupp'] = array
+(
+ 'label' => &$GLOBALS['TL_LANG']['tl_user']['iso_groupp'],
+ 'exclude' => true,
+ 'inputType' => 'checkbox',
+ 'options' => array('create', 'delete'),
+ 'reference' => &$GLOBALS['TL_LANG']['MSC'],
+ 'eval' => array('multiple'=>true, 'tl_class'=>'clr')
+);
View
35 system/modules/isotope/dca/tl_user_group.php
@@ -27,11 +27,12 @@
* @license http://opensource.org/licenses/lgpl-3.0.html
*/
+$this->loadLanguageFile('tl_iso_groups');
/**
* Extend a tl_user_group palette
*/
-$GLOBALS['TL_DCA']['tl_user_group']['palettes']['default'] = str_replace('{alexf_legend}', '{isotope_legend:hide},iso_modules,iso_product_types,iso_product_typep,iso_payment_modules,iso_payment_modulep,iso_shipping_modules,iso_shipping_modulep,iso_tax_classes,iso_tax_classp,iso_tax_rates,iso_tax_ratep,iso_mails,iso_mailp,iso_configs,iso_configp;{alexf_legend}', $GLOBALS['TL_DCA']['tl_user_group']['palettes']['default']);
+$GLOBALS['TL_DCA']['tl_user_group']['palettes']['default'] = str_replace('{alexf_legend}', '{isotope_legend:hide},iso_modules,iso_product_types,iso_product_typep,iso_payment_modules,iso_payment_modulep,iso_shipping_modules,iso_shipping_modulep,iso_tax_classes,iso_tax_classp,iso_tax_rates,iso_tax_ratep,iso_mails,iso_mailp,iso_configs,iso_configp,iso_groups,iso_groupp;{alexf_legend}', $GLOBALS['TL_DCA']['tl_user_group']['palettes']['default']);
/**
@@ -181,3 +182,35 @@
'eval' => array('multiple'=>true, 'tl_class'=>'w50 w50h')
);
+$GLOBALS['TL_DCA']['tl_user_group']['fields']['iso_groups'] = array
+(
+ 'label' => &$GLOBALS['TL_LANG']['tl_user']['iso_groups'],
+ 'exclude' => true,
+ 'inputType' => 'tableTree',
+ 'reference' => array
+ (
+ 'icon' => array
+ (
+ 'tl_iso_groups' => array('system/modules/isotope/html/folders.png', 'system/modules/isotope/html/folder-network.png')
+ )
+ ),
+ 'eval' => array
+ (
+ 'tableColumn' => 'tl_iso_groups.name',
+ 'fieldType' => 'checkbox',
+ 'title' => &$GLOBALS['TL_LANG']['tl_iso_groups']['label'],
+ 'children' => true,
+ 'tl_class' => 'clr'
+ )
+);
+
+$GLOBALS['TL_DCA']['tl_user_group']['fields']['iso_groupp'] = array
+(
+ 'label' => &$GLOBALS['TL_LANG']['tl_user']['iso_groupp'],
+ 'exclude' => true,
+ 'inputType' => 'checkbox',
+ 'options' => array('create', 'delete'),
+ 'reference' => &$GLOBALS['TL_LANG']['MSC'],
+ 'eval' => array('multiple'=>true, 'tl_class'=>'clr')
+);
+
View
2  system/modules/isotope/languages/de/tl_user.php
@@ -38,5 +38,7 @@
$GLOBALS['TL_LANG']['tl_user']['iso_configs'][1] = 'Nutzer können Bestellungen aus diesen Shop-Konfigurationen sehen.';
$GLOBALS['TL_LANG']['tl_user']['iso_modules'][0] = 'Isotope-Module';
$GLOBALS['TL_LANG']['tl_user']['iso_modules'][1] = 'Wählen Sie auf welche Shop-Konfigurationsmodule die Nutzer Zugriff haben.';
+$GLOBALS['TL_LANG']['tl_user']['iso_groups'][0] = 'Erlaubte Produktgruppen';
+$GLOBALS['TL_LANG']['tl_user']['iso_groups'][1] = 'Zugriff auf Produktegruppen für diese Benutzergruppe limitieren. Wird vererbt.';
$GLOBALS['TL_LANG']['tl_user']['isotope_legend'] = 'Isotope eCommerce';
View
2  system/modules/isotope/languages/en/tl_user.php
@@ -46,6 +46,8 @@
$GLOBALS['TL_LANG']['tl_user']['iso_mailp'] = array('Email template permissions', 'Here you can define the email template permissions.');
$GLOBALS['TL_LANG']['tl_user']['iso_configs'] = array('Allowed store configurations', 'Here you can grant access to one or more store configurations.');
$GLOBALS['TL_LANG']['tl_user']['iso_configp'] = array('Store configuration permissions', 'Her you can define the store configuration permissions.');
+$GLOBALS['TL_LANG']['tl_user']['iso_groups'] = array('Allowed product groups', 'Limit access to product groups for this user group. Gets inherited.');
+$GLOBALS['TL_LANG']['tl_user']['iso_groupp'] = array('Product group permissions', 'Here you can define the product group permissions.');
/**
View
79 system/modules/isotope/providers/PasteProductButton.php
@@ -10,12 +10,12 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
@@ -29,7 +29,13 @@
class PasteProductButton extends Backend
{
-
+ /**
+ * True if group already added
+ * @var bool
+ */
+ static private $blnHasGroup = false;
+
+
/**
* Handle the paste button callback for tl_iso_products
* @param DataContainer
@@ -47,7 +53,24 @@ public function generate(DataContainer $dc, $row, $table, $cr, $arrClipboard=fal
{
return '';
}
-
+
+ // make sure there's at least one product group
+ if (!self::$blnHasGroup)
+ {
+ if (IsotopeBackend::createGeneralGroup())
+ {
+ $this->reload();
+ }
+
+ self::$blnHasGroup = true;
+ }
+
+ // Can't do anything in root
+ if ($row['id'] == 0)
+ {
+ return '';
+ }
+
// Create a new product or variant
if ($arrClipboard['mode'] == 'create')
{
@@ -69,20 +92,20 @@ public function generate(DataContainer $dc, $row, $table, $cr, $arrClipboard=fal
return $this->pasteProduct($objProduct, $table, $row, $arrClipboard);
}
}
-
+
// Cut or copy multiple products. Cannot be variants because the checkbox is not available.
elseif ($arrClipboard['mode'] == 'cutAll' || $arrClipboard['mode'] == 'copyAll')
{
$objProduct = $this->Database->prepare("SELECT p.*, t.variants FROM tl_iso_products p LEFT JOIN tl_iso_producttypes t ON p.type=t.id WHERE p.id=?")->execute($arrClipboard['id']);
-
+
return $this->pasteAll($objProduct, $table, $row, $arrClipboard);
}
-
+
$this->Session->set('CLIPBOARD', null);
throw new Exception('Unhandled paste_button_callback mode "' . $arrClipboard['mode'] . '"');
}
-
-
+
+
/**
* Return paste button for new product
* @return string
@@ -94,11 +117,11 @@ protected function createProduct($table, $row, $arrClipboard)
{
return '';
}
-
+
return $this->getPasteButton(true, $this->addToUrl('act=create&amp;mode=2&amp;gid='.$row['id']), $table, $row['id']);
}
-
-
+
+
/**
* Return paste button for new variant
* @return string
@@ -110,7 +133,7 @@ protected function createVariant($table, $row, $arrClipboard)
{
return '';
}
-
+
// Disable paste button for products without variant data
elseif ($table == 'tl_iso_products' && $row['id'] > 0)
{
@@ -121,11 +144,11 @@ protected function createVariant($table, $row, $arrClipboard)
return $this->getPasteButton(false);
}
}
-
+
return $this->getPasteButton(true, $this->addToUrl('act=create&amp;mode=2&amp;pid='.$row['id']), $table, $row['id']);
}
-
-
+
+
/**
* Copy or paste a single product
* @return string
@@ -137,11 +160,11 @@ protected function pasteProduct(Database_Result $objProduct, $table, $row, $arrC
{
return '';
}
-
+
return $this->getPasteButton(true, $this->addToUrl('act='.$arrClipboard['mode'].'&amp;mode=1&amp;gid='.$row['id']), $table, $row['id']);
}
-
-
+
+
/**
* Copy or paste a single variant
* @return string
@@ -159,7 +182,7 @@ protected function pasteVariant(Database_Result $objProduct, $table, $row, $arrC
{
return $this->getPasteButton(false);
}
-
+
// Disable paste button for products without variant data
elseif ($table == 'tl_iso_products' && $row['id'] > 0)
{
@@ -170,11 +193,11 @@ protected function pasteVariant(Database_Result $objProduct, $table, $row, $arrC
return $this->getPasteButton(false);
}
}
-
+
return $this->getPasteButton(true, $this->addToUrl('act='.$arrClipboard['mode'].'&amp;mode=2&amp;pid='.$row['id']), $table, $row['id']);
}
-
-
+
+
/**
* Copy or paste multiple products
* @return string
@@ -186,11 +209,11 @@ protected function pasteAll($objProduct, $table, $row, $arrClipboard)
{
return '';
}
-
+
return $this->getPasteButton(true, $this->addToUrl('act='.$arrClipboard['mode'].'&amp;mode=1&amp;childs=1&amp;gid='.$row['id']), $table, $row['id']);
}
-
-
+
+
/**
* Return the paste button image
* @param bool
@@ -204,9 +227,9 @@ protected function getPasteButton($blnActive, $url='#', $table='', $id='')
{
return $this->generateImage('pasteinto_.gif', '', 'class="blink"');
}
-
+
$strImage = $this->generateImage('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $id), 'class="blink"');
-
+
return '<a href="'.$url.'" title="'.specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $id)).'" onclick="Backend.getScrollOffset();">'.$strImage.'</a> ';
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.