PHP-Code:
<?php
$GLOBALS['TL_DCA']['tl_dk_company_offer_category'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
'label' => &$GLOBALS['TL_LANG']['MOD']['dk_company_offers'][0],
'ctable' => array('tl_dk_company_offer'),
'enableVersioning' => true,
'sql' => array
(
'keys' => array
(
'id' => 'primary'
)
),
),
// List
'list' => array
(
'sorting' => array
(
'mode' => 5,
'fields' => array('sorting'),
'flag' => 1,
'panelLayout' => 'search',
'paste_button_callback' => array('tl_dk_company_offer_category', 'pasteTag'),
),
'label' => array
(
'fields' => array('title'),
'format' => '%s',
'label_callback' => array('tl_dk_company_offer_category', 'addIcon')
),
'global_operations' => array
(
'offers' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['offers'],
'href' => 'table=tl_dk_company_offer',
'attributes' => 'onclick="Backend.getScrollOffset();"',
'icon' => 'system/modules/dk_company_offers/assets/dummyicon.gif'
)
),
'operations' => array
(
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['edit'],
'href' => 'act=edit',
'icon' => 'edit.gif',
'button_callback' => array('tl_dk_company_offer_category','deactivateButtonForDefaultCategoryButNotForAdmin'),
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['copy'],
'href' => 'act=copy',
'icon' => 'copy.gif',
'button_callback' => array('tl_dk_company_offer_category','deactivateButtonForDefaultCategory'),
),
'cut' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['cut'],
'href' => 'act=paste&mode=cut',
'icon' => 'cut.gif',
'button_callback' => array('tl_dk_company_offer_category','deactivateButtonForDefaultCategory'),
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['tl_dk_company_offer_category']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"',
'button_callback' => array('tl_dk_company_offer_category','deleteButtonCallback'),
),
'toggle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['toggle'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => array('tl_dk_company_offer_category', 'toggleIcon')
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['show'],
'href' => 'act=show',
'icon' => 'show.gif'
)
)
),
// Palettes
'palettes' => array
(
'__selector__' => array('addImage'),
'default' => '{title_legend},title,description;{image_legend},addImage;{publish_legend},published'
),
// Subpalettes
'subpalettes' => array
(
'addImage' => 'singleSRC'
),
// Fields
'fields' => array
(
'id' => array
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'pid' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'" // dummy-feld das für Mode 5 benötigt wird (s.o.)
),
'tstamp' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'sorting' => array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['sorting'],
'flag' => 2,
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'title' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['title'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>255),
'sql' => "varchar(255) NOT NULL default ''"
),
'description' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['description'],
'exclude' => true,
'search' => true,
'inputType' => 'textarea',
'eval' => array('mandatory'=>true, 'maxlength'=>255),
'sql' => "varchar(255) NOT NULL default ''"
),
'addImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['addImage'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => array('submitOnChange'=>true),
'sql' => "char(1) NOT NULL default ''"
),
'singleSRC' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['singleSRC'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array('filesOnly'=>true, 'extensions'=>$GLOBALS['TL_CONFIG']['validImageTypes'], 'fieldType'=>'radio', 'mandatory'=>true),
'sql' => "varchar(255) NOT NULL default ''"
),
'published' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_dk_company_offer_category']['published'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('doNotCopy'=>true),
'sql' => "char(1) NOT NULL default ''"
)
)
);
class tl_dk_company_offer_category extends Backend
{
public function __construct()
{
parent::__construct();
$this->import('BackendUser', 'User');
}
public function pasteTag(DataContainer $dc, $row, $table, $cr, $arrClipboard=false)
{
$this->import('BackendUser', 'User');
$imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id']));
if ($row['id'] == 0)
{
// direkt in die Hauptebene sollen keine Kategorien eingefügt werden, denn diese stünden
// dann oberhalb der Defaultkategorie
return '';
}
return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || $cr) ? $this->generateImage('pasteafter_.gif').' ' : '<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&mode=1&pid='.$row['id'].'&id='.$arrClipboard['id']).'" title="'.specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])).'" onclick="Backend.getScrollOffset();">'.$imagePasteAfter.'</a> ';
}
public function deactivateButtonForDefaultCategory($row, $href, $label, $title, $icon, $attributes)
{
return ($row['id'] > 1 )? '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : '';
}
public function deactivateButtonForDefaultCategoryButNotForAdmin($row, $href, $label, $title, $icon, $attributes)
{
return ($this->User->isAdmin || $row['id'] > 1 )? '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : '';
}
public function deleteButtonCallback($row, $href, $label, $title, $icon, $attributes)
{
if ($row['id']<=1)
return '';
$result = $this->Database->prepare("SELECT count(1) AS count FROM tl_dk_company_offer WHERE pid=?")
->execute($row['id']);
return ($result->count == 0 )? '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : Image::getHtml(preg_replace('/\.gif$/i', '_.gif', $icon)).' ';
}
public function addIcon($row, $label, DataContainer $dc=null, $imageAttribute='', $blnReturnImage=false, $blnProtected=false)
{
return Image::getHtml('system/modules/dk_company_offers/assets/dummyicon'.($row['published'] ? '' : '_').'.gif').$label;
}
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
// die Sichtbarkeit der Hauptkategorie kann nur vom Admin geändert werden:
if (!$this->User->isAdmin && $row['id'] <= 1 )
return '';
if (strlen(Input::get('tid')))
{
$this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1));
$this->redirect($this->getReferer());
}
// Check permissions AFTER checking the tid, so hacking attempts are logged
if (!$this->User->isAdmin && !$this->User->hasAccess('tl_dk_company_offer_category::published', 'alexf'))
{
return '';
}
$href .= '&tid='.$row['id'].'&state='.($row['published'] ? '' : 1);
if (!$row['published'])
{
$icon = 'invisible.gif';
}
return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ';
}
public function toggleVisibility($intId, $blnVisible)
{
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_dk_company_offer_category']['fields']['published']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_dk_company_offer_category']['fields']['published']['save_callback'] as $callback)
{
$this->import($callback[0]);
$blnVisible = $this->$callback[0]->$callback[1]($blnVisible, $this);
}
}
// Update the database
$this->Database->prepare("UPDATE tl_dk_company_offer_category SET tstamp=". time() .", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")
->execute($intId);
}
}
?>
Lesezeichen