<?php

/*
 * This file is part of newsmailer bundle for Contao.
 *
 * (c) Benjamin Roth
 *
 * @license LGPL-3.0-or-later
 */

use Contao\CoreBundle\DataContainer\PaletteManipulator;

/**
 * Palettes
 */

//$GLOBALS['TL_DCA']['tl_news']['palettes']['default'] = str_replace(array('{publish_legend}','{publish_legend:hide}'),array('{nc_legend:hide},nc_sent,nc_testmail;{publish_legend}','{nc_legend:hide},nc_sent,nc_testmail;{publish_legend:hide}'),$GLOBALS['TL_DCA']['tl_news']['palettes']['default']);
PaletteManipulator::create()
    ->addLegend('nc_legend','publish_legend',PaletteManipulator::POSITION_BEFORE)
    ->addField('nc_sent','nc_legend', PaletteManipulator::POSITION_APPEND)
    ->addField('nc_testmail','nc_legend', PaletteManipulator::POSITION_APPEND)
    ->applyToPalette('default','tl_news')
;

/**
 * Fields
 */

$GLOBALS['TL_DCA']['tl_member']['fields']['nc_news_subscribe'] = array
(
    'exclude'                 => true,
    'inputType'               => 'checkbox',
    'eval'                    => array('tl_class'=>'w50 m12', 'doNotCopy'=>true, 'feEditable'=>true, 'feViewable'=>true, 'feGroup'=>'contact'),
    'save_callback'           => array
    (
        array('tl_member_eSM_nc_news', 'setNcNewsChangedate'),
    ),
    'sql'                     => "char(1) NOT NULL default '1'"
);

$GLOBALS['TL_DCA']['tl_member']['fields']['nc_news_subscribe_changed'] = array
(
    'eval'                    => array('rgxp'=>'datim'),
    'sql'                     => "int(10) unsigned NOT NULL default '0'"
);

$GLOBALS['TL_DCA']['tl_member']['fields']['nc_news_additionalEmail'] = array
(
    'exclude'                 => true,
    'search'                  => true,
    'inputType'               => 'text',
    'eval'                    => array('mandatory'=>false, 'maxlength'=>1022, 'rgxp'=>'emails', 'tl_class'=>'w50', 'feEditable'=>true, 'feViewable'=>true, 'feGroup'=>'contact'),
    'sql'                     => "varchar(1022) NOT NULL default ''"
);